Re: [R] Efficient way to find consecutive integers in vector?

From: Gabor Csardi <csardi_at_rmki.kfki.hu>
Date: Thu, 20 Dec 2007 23:11:18 +0100

Joh,

x <- c(1,2,3,4,7,8,9,10,12,13)
which(diff(x) != 1)

gives the indices of the 'jumps'.

Gabor

On Thu, Dec 20, 2007 at 10:43:05PM +0100, Johannes Graumann wrote:
> Hi all,
>
> Does anybody have a magic trick handy to isolate directly consecutive
> integers from something like this:
> c(1,2,3,4,7,8,9,10,12,13)
>
> The result should be, that groups 1-4, 7-10 and 12-13 are consecutive
> integers ...
>
> Thanks for any hints, Joh
>
> ______________________________________________
> R-help_at_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.

-- 
Csardi Gabor <csardi_at_rmki.kfki.hu>    MTA RMKI, ELTE TTK

______________________________________________
R-help_at_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.
Received on Thu 20 Dec 2007 - 22:14:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 20 Dec 2007 - 22:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.