I'm trying to subset a data frame to all rows for which a certain column value is '13', but I want all rows preceding a row with '13' to be included too, no matter the value in that column.
I do not want a row to be included twice when it both precedes a row with '13' in the specific column, but also has the value '13' itself.
Here is an example data frame and solution, whereby the condition (subset rows to rows with time = 13 and (time=13)-1, without duplicating)
ID speed dist time
A 4 12 4
B 7 10 8
C 7 18 13
C 8 4 5
A 5 6 13
D 6 2 13
E 7 2 9
Becomes
ID speed dist time
B 7 10 8
C 7 18 13
C 8 4 5
A 5 6 13
D 6 2 13