New to R and would like to do the following operation: I have a set of numbers e.g. (1,1,0,1,1,1,0,0,1) and need to count adjacent duplicates as they occur. The result I am look
We can use rle
rle
rle(v1)$lengths #[1] 2 1 3 2 1
v1 <- c(1,1,0,1,1,1,0,0,1)