I am a little perplex based on a specific data manipulation I want to perform. I want to look for animals with a specific Id repeated over time t where they can be treated (variable Treat==1) or not (Treat==0). The dataframe bd I have is the following example:
bd =data.frame(t=c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6), #6 measurement periods for the individuals
Id= rep(1:18, each=6, length.out=18), #3 individuals repeated over time
Treat=c(0,0,1,0,0,0, 0,0,0,0,1,0,0,0,0,0,0,0) # variable indicating if the animal was treated for this period of time yes if 1 and no if 0
) # I want to keep rows of the Id starting from Treat==1.
In the end I want to keep :for individual 1 the rows starting where Treat=="1" (ie row of Id=1 and t from t=3 to t=6, for Id=2, the rows with t=5 and t=6 and no row for Id=3 because Treat==0.
Thanks for your help!!!