Re: [R] plyr: colvar value corresponding to max Date

2014-02-15 Thread Dan Murphy
Thank you A.K. and Ista. The answer that eliminates duplicated rows is A.K.'s first solution (brilliant idea using which.max!). The version of Ista's solution without duplicates is ddply(data, "state", function(x) x[which.max(x$date), ])$value Thanks again! Dan On Thu, Feb 13, 2014 at 8:36 AM, aru

Re: [R] plyr: colvar value corresponding to max Date

2014-02-13 Thread arun
Hi, Try ?which.max() # unique values for the combination.  ddply(data,.(state),summarize,max_date=value[which.max(date)])[,2] #or  ddply(data,.(state),summarize,max_date=value[date == max(date)])[,2] A.K. On Thursday, February 13, 2014 11:15 AM, Dan Murphy wrote: I can do this in multiple st

Re: [R] plyr: colvar value corresponding to max Date

2014-02-13 Thread Ista Zahn
ddply(data, "state", function(x) x[x$date == max(x$date), ])$value On Thu, Feb 13, 2014 at 11:13 AM, Dan Murphy wrote: > I can do this in multiple steps with summarise, joins, etc., but can't > help thinking it can be accomplished in one plyr call. > > Here's a small example: > >> require(plyr) >

[R] plyr: colvar value corresponding to max Date

2014-02-13 Thread Dan Murphy
I can do this in multiple steps with summarise, joins, etc., but can't help thinking it can be accomplished in one plyr call. Here's a small example: > require(plyr) > require(lubridate) > data <- data.frame( + date = rep(as.Date(ymd(20140101 + (0:3) * 100)), 2), + state = rep(c("A", "B"), ea