Skip to content
Prev 304062 / 398506 Next

Extracting data from dataframe with tied rows

Or use ave() to compute the within-group ranks (reversed, so max has rank 1) and select
the elements whose ranks are 1:
f2 <- function (DATA) 
{
    stopifnot(is.data.frame(DATA), all(c("distance", "id", "month") %in% 
        names(DATA)))
    revRanks <- ave(DATA[["distance"]], DATA[["id"]], DATA[["month"]], 
        FUN = function(x) rank(-x, ties = "first"))
    DATA[revRanks == 1, ]
}

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com