I'm trying to select 100 rows before and after a marker in a relatively large dataframe. The markers are sparse and for some reason I haven't been able to figure it out or find a solution - this doesn't seem like it should be that hard, so I'm probably missing something obvious.
Here's a very small simple example of what the data looks like:
timestamp talking_yn transition_yn
0.01 n n
0.02 n n
0.03 n n
0.04 n n
0.05 n n
0.06 n n
0.07 n n
0.08 n n
0.09 n n
0.10 n n
0.11 y y
0.12 y n
0.13 y n
0.14 y n
0.15 y n
0.16 y n
0.17 y n
0.18 y n
I've tried using different methods from a variety of answers (lag
from zoo
or dplyr
), but they all focus on selecting one row or subsetting only those rows with the marker. For the dummy example data, how would I select the 5 rows before and after the transition == 'y'
row?