If I have the below dataset:
df<-data.frame(ID = c(1,1,1,1,2,2,2,2),
x = c("no","yes","no","no","no","yes", "no"),
y= c(1,2,3,4,1,2,3,4))
| ID | x | y |
|---|---|---|
| 1 | no | 1 |
| 1 | yes | 2 |
| 1 | no | 3 |
| 1 | no | 4 |
| 2 | no | 1 |
| 2 | no | 2 |
| 2 | yes | 3 |
| 2 | no | 4 |
ID is an identifier, x tells us whether or not a condition has been met, and y is a time order unique to each ID (though in a real data set it would probably be a date). How can I remove rows where the condition was not met but keep rows where the condition was met, or the event occurred after the condition was met?
A final result should look like this:
| ID | x | y |
|---|---|---|
| 1 | yes | 2 |
| 1 | no | 3 |
| 1 | no | 4 |
| 2 | yes | 3 |
| 2 | no | 4 |