Here, I made a simple data to demonstrate what I want to do.
df<-data.frame(id=c(1,1,1,2,2,2,2,3,3),
date=c(20220311,20220315,20220317,20220514,20220517,20220518,20220519,20220613,20220618),
disease=c(0,1,0,1,1,1,0,1,1))
id stands for a personal id. disease=1 means that person has a disease. disease=0 means that person doesn't have a disease.There are 3 people in df.For id equals 1, the first row of the value of disease is 0. On the other hand, the first two rows of the value of disease for id 2 and 3 are 1. I want to extract the data if the first row of each id is 1.
So, I should extract the data with id 2 and 3. My expected output is
df<-data.frame(id=c(2,2,2,2,3,3),
date=c(20220514,20220517,20220518,20220519,20220613,20220618),
disease=c(1,1,1,0,1,1))