On Mon, Nov 22, 2010 at 3:39 PM, Tan, Richard <r...@panagora.com> wrote: > Hi, I am trying to aggregate max a Date type column but have weird > result, how do I fix this? > >> a <- rbind( > > + data.frame(name='Tom', payday=as.Date('1999-01-01')), > + data.frame(name='Tom', payday=as.Date('2000-01-01')), > + data.frame(name='Pete', payday=as.Date('1998-01-01')), > + data.frame(name='Pete', payday=as.Date('1999-01-01')) > + ) >
Since its already sorted try this: a[!duplicated(a$name, fromLast = TRUE), ] Using sqldf also works: library(sqldf) sqldf("select name, max(payday) payday from a group by name order by name") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ 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.