Hi I have something like:
df<-data.frame(group=c(1, 1, 1, 1, 2, 2, 2,3,3,3,4,4,4),
number=c(0,1,1,1,1,1,0,1,0,1,0,1,1))
I want my 'want' to count the times 'number'=1 repeats per 'group'. Then I want the max number of times it repeats (want2). I want the 'want' to reset to 1 when 'number'=0:
dfwant<-data.frame(group=c(1, 1, 1, 1, 2, 2, 2,3,3,3,4,4,4),
number=c(0,1,1,1,1,1,0,1,0,1,0,1,1),
want=c(1,1,2,3,1,2,1,1,1,1,1,1,2),
want2=c(3,3,3,3,2,2,2,1,1,1,2,2,2))
Thank you!