I have a dataframe with counts of different items, in different years:
df <- data.frame(item = rep(c(\'a\',\'b\',\'c\'), 3), year = rep(c
While using the answers given by others, I found that the following performs faster than the transform and dyplr variants:
df$year.rank <- ave(count, year, FUN = function(x) rank(-x, ties.method = "first"))