**From:** Ravi Varadhan (*rvaradha@jhsph.edu*)

**Date:** Thu 20 May 2004 - 03:26:04 EST

**Next message:**Diethelm Wuertz: "[R] FAQ for Rmetrics"**Previous message:**Han-Lin Lai: "[R] mixed models for analyzing survey data with unequal selection probability"**Next in thread:**Petr Pikal: "Re: [R] Finding indices where"**Reply:**Petr Pikal: "Re: [R] Finding indices where"

Message-id: <a0e726a0c5a1.a0c5a1a0e726@jhsph.edu>

Hi:

Suppose I have the following vector:

*> x <- c(1,4:8,11,13:14,17,19,23:28,35:38)
*

*> x
*

[1] 1 4 5 6 7 8 11 13 14 17 19 23 24 25 26 27 28 35 36 37 38

*>
*

and I would like to pick out the first and last indices of all the

consecutive "runs" of integers, where the length of a run is no smaller

than a specified value, say, nmin. That is, in the above example, for

nmin=4, I would like to get the following 3 by 2 matrix:

4 8

23 28

35 38

For nmin=5, I would get the following 2 by 2 matrix

4 8

23 28

and for nmin=6, I would get the following 1 by 2 matrix

23 28

Is there an efficient and elegant way to do this?

Thanks very much for any help/suggestions.

Ravi.

______________________________________________

R-help@stat.math.ethz.ch mailing list

https://www.stat.math.ethz.ch/mailman/listinfo/r-help

PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

**Next message:**Diethelm Wuertz: "[R] FAQ for Rmetrics"**Previous message:**Han-Lin Lai: "[R] mixed models for analyzing survey data with unequal selection probability"**Next in thread:**Petr Pikal: "Re: [R] Finding indices where"**Reply:**Petr Pikal: "Re: [R] Finding indices where"

*
This archive was generated by hypermail 2.1.3
: Mon 31 May 2004 - 23:05:11 EST
*