I have an R dataframe like the one below which contains each user and a list of days they were active.
User date_active
1 2018-08-27
1 2018-08-28
1 2018-08-29
1 2018-08-31
1 2018-09-01
2 2018-07-05
2 2018-07-06
2 2018-07-07
2 2018-07-08
2 2018-07-10
2 2018-07-11
2 2018-07-12
2 2018-07-20
I would like to count all the dates up until a gap, in which the count restarts. My expected output would look like the below table for the above data.
User date_active
1 3
1 2
2 4
2 3
2 1
My initial guess was to use the rank
function or difftime
but am unsure how to get the result. Any help would be most appreciated!