Trying to extract the first occurrence of a variable in a data frame PRIOR to a specific value already selected in a data frame. Specifically, the output of head(df)
is:
date discharge event event.isolation some.column
1/1/2016 7.782711 NA NA FALSE
1/2/2016 7.349389 -5.567748 none TRUE
1/3/2016 7.053813 -4.021769 none TRUE
1/4/2016 7.421568 5.213554 none TRUE
1/5/2016 5.722443 -22.894418 none TRUE
1/6/2016 5.497342 -3.933662 none TRUE
1/7/2016 5.347890 -6.898281 none TRUE
1/8/2016 7.983489 4.289382 none TRUE
1/9/2016 8.488293 -19.28304 none TRUE
I'd like to find the date
of the first discharge
value of 7.7 or greater before each event
of -22 or less. In other words, I know each event
of interest; I would like to iteratively search backwards to find the first discharge
value of 7.7 or greater prior to each selected event
.
I'm basically trying to combine Extract rows for the first occurrence of a variable in a data frame with Select row prior to first occurrence of an event by group, but am having difficulty so.
The desired result would be df[1, ]
as it contains the first discharge
value (working backwards) that exceeds 7.7, prior to the event
in row 5 that I've selected.