Create a ranking variable with dplyr?

后端 未结 2 837
生来不讨喜
生来不讨喜 2020-12-04 16:24

Suppose I have the following data

df = data.frame(name=c(\"A\", \"B\", \"C\", \"D\"), score = c(10, 10, 9, 8))

I want to add a new column w

2条回答
  •  盖世英雄少女心
    2020-12-04 17:07

    Other solution when you need to apply the rank to all variables (not just one).

    df = data.frame(name = c("A","B","C","D"),
                    score=c(10,10,9,8), score2 = c(5,1,9,2))
    
    select(df, -name) %>% mutate_all(funs(dense_rank(desc(.))))
    

提交回复
热议问题