On 19-10-2013, at 02:17, "Benton, Paul" <hpaul.bento...@imperial.ac.uk> wrote:

> Hello all,
> 
> I'm not really sure how to search for this in google/Rseek so there is 
> probably a command to do it. I also know I could write an apply loop to find 
> it but thought I would ask all you lovely R gurus. 
> 
> I have a very long vector (length=1855190) it looks something like this
> 
> 1111...2222...3333....etc so it would be something equivalent of doing:
> rep(c(1,2,3,4,5), c(10,30,24,65,3))
> 
> How can I find the index of where the step/jump is? For example using the 
> above I would get an index of 0, 10, 40, 64, 129
> 
> Any help would be greatly appreciated.


z <- rep(c(1,2,3,4,5), c(10,30,24,65,3))
cumsum(rle(z)$lengths) 

Berend

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to