0

Let us consider a vector x, where

 x=c(1,2,2,2,2,3,3,4,5,5,5,6,7,7,7).

I want to get the run vector (y) obtained from the above vector, that is,

y= 1 4 2 1 3 1 3.

I think there may be a function in R to do this task but I don't that function. Could anyone please suggest me what function do this task in R. Thanks in advance.

Janak
  • 653
  • 7
  • 25
  • 2
    `rle(x)$lengths` is what you are looking for – Cath Mar 19 '15 at 12:39
  • 1
    http://stackoverflow.com/questions/1502910/how-can-i-count-runs-in-a-sequence – rawr Mar 19 '15 at 12:40
  • Thanks to all for the answer....I was guessing there may be answer in stackoverflow...but could not found it. Anyway thanks, I got the answer. – Janak Mar 19 '15 at 12:48

0 Answers0