I have problems wrapping my head around this problem without writing an excessive code with a ton of ifs.
Suppose you have a dataset:
library(dplyr) t = tibble(Time = c(1:100), Value = sample(c(rep(1, 50), rep(0, 50))))
Your goal is to find every sequence of 1s occuring on 4 or more subsequent rows for the Value column. So for example rows 1,1,1,1,1 would be a hit but 1,0,1,1,1 not. For every such sequence, you need to store the value of Time for the first occurring 1 as well as for the last occurring 1 of this sequence. For example in a tibble
result = tibble(mintime, maxtime) . Note, there will be multiple such sequences and the number of subsequent 1 can vary widely, so the solution should be generalizable for sequences 4:n.