Re: [R] Counting indexes

2010-05-26 Thread Alan Lue
x - rle(id) cumsum(x$lengths) - (x$lengths - 1) cumsum(x$lengths) Alan On Tue, May 25, 2010 at 10:00 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: This assumes that for a particular id they all occur together in a run: cbind(start = which(!duplicated(id)), end = which(!duplicated(id,

[R] Counting indexes

2010-05-25 Thread Robin Jeffries
Hallo! I have a vector of ID's like so, id - c(1,2,2,3,3,3,4,5,5) I would like to create a [start,stop] pair of vectors that index the first and last observation per ID. For the ID list above, it would look like 1 1 2 3 4 6 7 7 8 9 I haven't worked with indexes/data manipulation much in R, so

Re: [R] Counting indexes

2010-05-25 Thread Peter Alspach
Of Robin Jeffries Sent: Wednesday, 26 May 2010 4:15 p.m. To: r-help@r-project.org Subject: [R] Counting indexes Hallo! I have a vector of ID's like so, id - c(1,2,2,3,3,3,4,5,5) I would like to create a [start,stop] pair of vectors that index the first and last observation per ID

Re: [R] Counting indexes

2010-05-25 Thread Erik Iverson
Robin Jeffries wrote: Hallo! I have a vector of ID's like so, id - c(1,2,2,3,3,3,4,5,5) I would like to create a [start,stop] pair of vectors that index the first and last observation per ID. For the ID list above, it would look like 1 1 2 3 4 6 7 7 8 9 which(!duplicated(id)) [1] 1 2 4 7 8

Re: [R] Counting indexes

2010-05-25 Thread Robin Jeffries
Awesome! Thanks:) On Tue, May 25, 2010 at 9:40 PM, Erik Iverson er...@ccbr.umn.edu wrote: Robin Jeffries wrote: Hallo! I have a vector of ID's like so, id - c(1,2,2,3,3,3,4,5,5) I would like to create a [start,stop] pair of vectors that index the first and last observation per ID.

Re: [R] Counting indexes

2010-05-25 Thread Gabor Grothendieck
This assumes that for a particular id they all occur together in a run: cbind(start = which(!duplicated(id)), end = which(!duplicated(id, fromLast = TRUE))) start end [1,] 1 1 [2,] 2 3 [3,] 4 6 [4,] 7 7 [5,] 8 9 On Wed, May 26, 2010 at 12:14 AM, Robin