I want to rank each hour value within each individual id. The hour values that equal each other will be the same rank. I attempted to do this with the row count function (.N) in data.table. I was hoping this would work but I cannot figure it out.
Here is a reproducible example, please let me know if you have any questions about my problem.
library(data.table)
dt <- data.table(hours=c(100, 72, 48, 98, 87, 75, 98, 75, 52, 48, 100, 98, 87, 35, 48, 75, 92, 100, 75, 48),
id=rep(1:4, each=5, 1))
dt <- dt[, list(.(hours <= hours), .N), list(hours, id)]
Desired output
Any help will be greatly appreciated.
