Let us consider a binary sequence like the following
00001001110000011000000111111
I would like to count the repeated 1s in the sequence, as follows
00001001230000012000000123456
I was thinking of the following solution
> b<-c(0,0,0,0,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1)
> rle(b)
Run Length Encoding
lengths: int [1:8] 4 1 2 3 5 2 6 6
values : num [1:8] 0 1 0 1 0 1 0 1
but the result in "lengths" and "num" do not apply to my case.