Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 202012

Insert rows based on difference between value from col A row N and col B row N+1

$
0
0

I have data with an example as follows (I use R):

A   B   C
1   2   Background
3   19  Background
26  41  person
43  69  person
83  97  Background
107 129 Background
132 179 Background
189 235 Background
243 258 Background
261 279 person

I would like to add rows where the difference between col A row N+1 and col B row N > 1 and row C gets a label (e.g. 'other'). So the data would look like this:

A   B   C
1   2   Background
3   19  Background
20  25  other
26  41  person
43  69  person
70  82  other
83  97  Background
98  106 other
107 129 Background
130 131 other
132 179 Background
180 188 other
189 235 Background
236 242 other
243 258 Background
259 260 other
261 279 person

Thanks!


Viewing all articles
Browse latest Browse all 202012

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>