I have the following dataframe and wish to extract all rows corresponding to the same group with status==1.
The status column is either 0 or 1.
df<-data.frame(time= rep(1:4,times=c(2,3,5,4)),status=c(0,0,1,1,0,0,0,0,0,0,1,0,0,0))
Input Data
time status
1 1 0
2 1 0
3 2 1
4 2 1
5 2 0
6 3 0
7 3 0
8 3 0
9 3 0
10 3 0
11 4 1
12 4 0
13 4 0
14 4 0
Desired output (with renumbering the group column in sequence).
time status
1 1
1 1
1 0
2 1
2 0
2 0
2 0
The dimension of my actual data.frame is in order of 10^6 by 5.
Thank you for your help.
Hm, so you want to get the group two and four since both these groups have a status one value, correct? And from those two groups you like to get the whole output?
If so,how about this:
edit: