Use dplyr::percent_rank() to compute percentile ranks within group

前端 未结 1 1498
花落未央
花落未央 2021-02-05 22:25

Suppose I have the following data:

id    grpvar1    grpvar2    value
1     1          3          7.6
2     1          2          4
...
3     1          5                 


        
1条回答
  •  梦谈多话
    2021-02-05 22:47

    Try:

     library(dplyr)
     dataf %>%
     group_by(grpvar1, grpvar2) %>% 
     mutate(percrank=rank(value)/length(value))
    

    0 讨论(0)
提交回复
热议问题