Skip to content

Aggregate dataframe variables, return more than 2 vars

2 messages · violet lock, Martin Maechler

#
Not at all appropriate to be posted to R-devel :
> Hello r-devel,
    > I have data.frame with 3 columns and I would like to group by 1 column(id),
    > find the max of the third column (date) and return the data for that max
    > date value along with the id and the value in the second column.

    > Example:
    >> dat <- data.frame(id = rep(1:3, 3), date = as.Date(rep(c("2005-08-25",
    > "2005-08-26", "2005-08-29"), each = 3)), decod = c("SCREEN", "SCREEN",
    > "SCREEN", "RAND", "RAND", "RAND", "COMPLETE", "COMPLETE", "WITHDRAWAL")  )


    > What I need is it to return is:


[...............]
[...............]


    > Any ideas would be appreciated,

E-mails that look like the above *CLEARLY* belong to  R-help
and *NEVER* to  R-devel.

Please read the posting guide
and *then* repost to R-help!

Martin Maechler, ETH Zurich