dat <- data.frame(id = c(1,1,1,2,2), value = c(5,6,7,4,5), value2 =
c(1,4,3,3,4))
with(dat, dat[!duplicated(id),])

Michael

On Sun, Sep 25, 2011 at 4:43 PM, AC Del Re <acdelre@gmail.com> wrote:

> Great but how can I then retain the other variable (or variables if >1)
> value associated with those retained values?
> thank you.
>
> On Sun, Sep 25, 2011 at 1:27 PM, R. Michael Weylandt <
> michael.weylandt@gmail.com> wrote:
>
>> How about something like
>>
>> with(dat, value[!duplicated(id)])
>>
>> ?
>>
>> Michael Weylandt
>> On Sun, Sep 25, 2011 at 4:22 PM, AC Del Re <delre@wisc.edu> wrote:
>>
>>> Hi,
>>>
>>> I am trying to select the first row of a variable with data in
>>> long-format,
>>> e.g.,
>>>
>>> # sample data
>>> id <- c(1,1,1,2,2)
>>> value <- c(5,6,7,4,5)
>>> dat <- data.frame(id, value)
>>> dat
>>>
>>> How can I select/subset the first 'value'  for each unique 'id'?
>>>
>>> Thanks,
>>>
>>> AC
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help@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.
>>>
>>
>>
>

	[[alternative HTML version deleted]]

