Skip to content
Prev 336589 / 398513 Next

plyr: colvar value corresponding to max Date

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:
+   date = rep(as.Date(ymd(20140101 + (0:3) * 100)), 2),
+   state = rep(c("A", "B"), each = 4),
+   value = rnorm(8))

What I want is clearly
[1] -1.007111 -1.527541

Here are my multiple steps:
[1] -1.007111 -1.527541

Is there a one-step way to accomplish this?
Something like
ddply(data, "state", summarise, "GiveMeTheValueCorrespondingToMaxDateByState!!")

Or is that only possible if there is only one unique value for a given
combination of state and max(date)?

Thanks,
Dan