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

R code to assign a sequence based off of multiple variables [duplicate]

$
0
0

This question already has an answer here:

I have data structured as below:

ID   Day   Desired Output
1    1      1
1    1      1
1    1      1
1    2      2
1    2      2
1    3      3
2    4      1
2    4      1
2    5      2
3    6      1
3    6      1

Is it possible to create a sequence for the desired output without using a loop? The dataset is quite large so a loop won't work, is it possible to do this with the dplyr package or maybe a combination of cumsum/diff?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



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