Suppose I have the following data:
id grpvar1 grpvar2 value 1 1 3 7.6 2 1 2 4 ... 3 1 5
Try:
library(dplyr) dataf %>% group_by(grpvar1, grpvar2) %>% mutate(percrank=rank(value)/length(value))