I am trying to make the rest of visit value to 1 if the previous value is 1 within the same id, but just can't find a good way without a bunch of slow for loops.
Here is the example:
data.frame(ID = c(1,1,1,1,1,2,2,2,2,2,2,3,3,3),
Visit = c(1,2,3,4,5,1,2,3,4,5,6,1,2,3),
Value = c(0,0,1,0,0,0,0,0,0,1,0,0,1,0))
And here is what I want to get:
data.frame(ID = c(1,1,1,1,1,2,2,2,2,2,2,3,3,3),
Visit = c(1,2,3,4,5,1,2,3,4,5,6,1,2,3),
Value = c(0,0,1,1,1,0,0,0,0,1,1,0,1,1))
Thanks in advance!