Re: [R] Subsetting to unique values

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Fri, 06 Jun 2008 15:57:37 -0400

Dear Paul,

Try also:

ddTable <-
 data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry"))

ddTable[unique(ddTable$Id),]

HTH, Jorge

On Fri, Jun 6, 2008 at 9:35 AM, Emslie, Paul [Ctr] <emsliep_at_atac.mil> wrote:

> I want to take the first row of each unique ID value from a data frame.
> For instance
> > ddTable <-
> data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry"))
>
> I want a dataset that is
> Id Name
> 1 Paul
> 2 Bob
>
> > unique(ddTable)
> Will give me all 4 rows, and
> > unique(ddTable$Id)
> Will give me c(1,2), but not accompanied by the name column.
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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 Fri 06 Jun 2008 - 20:40:39 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 Fri 06 Jun 2008 - 21:30:58 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.

list of date sections of archive