[R] Identifying sequences

David Winsemius dwinsemius at comcast.net
Wed Jun 1 14:28:15 CEST 2011


On Jun 1, 2011, at 6:27 AM, christiaan pauw wrote:

> Hallo Everybody
>
> Consider the following vector
>
> a=1:10
> b=20:30
> c=40:50
> x=c(a,b,c)
>
> I need a function that can tell me that there are three set of  
> continuos
> sequences and that the first is from 1:10, the second from 20:30 and  
> the
> third from 40:50. In other words: a,b, and c.

You probably want something like

 > which(diff(x) >1)
[1] 10 21

Or perhaps what the rle function provides.

?diff
?rle

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list