[R] Subsetting to unique values

John Kane jrkrideau at yahoo.ca
Fri Jun 6 16:22:23 CEST 2008


I don't have R on this machine but will this work.  
myrows <- unique(ddTable[,1])
unis <- ddTable(myrows, ]


--- On Fri, 6/6/08, Emslie, Paul [Ctr] <emsliep at atac.mil> wrote:

> From: Emslie, Paul [Ctr] <emsliep at atac.mil>
> Subject: [R] Subsetting to unique values
> To: r-help at r-project.org
> Received: Friday, June 6, 2008, 9:35 AM
> 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.



More information about the R-help mailing list