Awesome! Thanks:)



On Tue, May 25, 2010 at 9:40 PM, Erik Iverson <eriki@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.
>>
>> 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
>
> cumsum(rle(id)$lengths)
> [1] 1 3 6 7 9
>

	[[alternative HTML version deleted]]

