I am trying to find 'x' or more consecutive missing dates for each group in R. My current approach involves:
- Using a for loop over each group
- Find missing dates
- Find how many of these missing dates are consecutive (here I get a logical vector, saying where the missing dates are consecutive or not.
This is where I am stuck. How to check from the logical vector, if "TRUE" occurs consecutively for 'x' number of times or higher.
logical_vector <- c("TRUE", "TRUE", "TRUE", "FALSE", "TRUE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE")
For example, in the above vector, how do you check if the value "TRUE" occurred 4 times or higher consecutively?
I think it is something very easy, but I cant figure this out and have been stuck for a while. Especially since the 'x' number of times or higher condition needs to be satisfied.
If it does occur 4 times or higher, should we store that as a logical vector as well?
Any help is appreciated.