Thank you! -----Original Message----- From: Chel Hee Lee [mailto:chl...@mail.usask.ca] Sent: Friday, January 23, 2015 8:09 PM To: Tan, Richard; 'r-help@R-project.org' Subject: Re: [R] get latest dates for different people in a dataset
> do.call(rbind, lapply(split(data, data$Name), function(x) x[order(x$CheckInDate),][nrow(x),])) Name CheckInDate Temp John John 2014-04-01 99.0 Mary Mary 2014-03-01 98.1 Sam Sam 2014-04-01 97.5 > Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/23/2015 05:43 PM, Tan, Richard wrote: > Hi, > > Can someone help for a R question? > > I have a data set like: > > Name CheckInDate Temp > John 1/3/2014 97 > Mary 1/3/2014 98.1 > Sam 1/4/2014 97.5 > John 1/4/2014 99 > > I'd like to return a dataset that for each Name, get the row that is > the latest CheckInDate for that person. For the example above it > would be > > Name CheckInDate Temp > John 1/4/2014 99 > Mary 1/3/2014 98.1 > Sam 1/4/2014 97.5 > > > Thank you for your help! > > Richard > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.