Excel: Consecutive 3 Occurrences or more of a value in a string

Using Base R:
rle function compute the lengths and values of runs of equal values in a vector.

x <- c(1 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,1 ,1)
rlx <- rle(x)

rlx
Run Length Encoding
    lengths: int [1:9] 1 3 2 2 1 1 1 4 2
    values : num [1:9] 1 0 1 0 1 0 1 0 1

sum(rlx$lengths[x==0] >=3, na.rm = TRUE)
[1] 2

PS: @Mr. Down voter answer posted as OP “Original post” includes R tag.

Leave a Comment