I want to identify the first time a value of zero occurs in the following example code by group (spec, freq) and create change that corresponding row within column "threshold" to "yes". In other words, for each unique group of greq and spec there would be just one "yes". Ideally, I want to modify this to:
- the first zero followed by another zero, or
- the row above the first zero within the group
Example code:
df <- data.frame(response = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1,
0, 1, 0, 0),
spec = c("a", "a", "a", "a", "a", "a", "a","a","a","a",
"b", "b", "b", "b", "b", "b", "b", "b", "b", "b"),
freq = c(100, 100, 100, 100, 100, 200, 200, 200, 200, 200,
100, 100, 100, 100, 100, 200, 200, 200, 200, 200))
df$thresh <- "no"
Any help would be very appreciated. Note response values are arbitrary binary values and can be changed if that makes things easier.