I've searched around but haven't been able to find a solution to my question yet. I'm not really sure where to start.
I have a numeric vector in R. For example:
vec<-c(8,1,2,5,20,1,6,7,13,1,8,1,14,1,1,4,2,7)
I'm looking to find the index where the value '1' occurs at least 3 times within a window of 5. So in the above example, the output would be '10' as the window containing '1,8,1,14,1' is the first sequence of 5 values where 3 values are '1' and the index of the start of that sequence is 10.
Any help would be appreciated.