detect successive repetitions in R
r
Solution
You can use `rle` for this:
> rle(A)
Run Length Encoding
lengths: int [1:4] 1 1 2 1
values : num [1:4] 1 2 3 4
> any(rle(A)$lengths > 1)
[1] TRUE
> any(rle(B)$lengths > 1)
[1] FALSE
Problem
in R, I would like to find out whether there are successive repetitions in my data. ``` A <- c(1,2,3,3,4) B <- c(1,2,3,4,3) ``` For A, I want to get TRUE, since there are two 3s directly one after the other. For B, I want to get FALSE because the 3s are separated by the 4. Thanks community! pointingeye