dplyr equivalent to ddply in plyr diamonds example

前端 未结 2 1049
执笔经年
执笔经年 2021-01-12 22:32

ok, I\'m trying to wrap my head around dplyr, using it instead of plyr. In my short time with R I\'ve grown somewhat accustomed to ddply. I\'m using a \"simple\" example fo

2条回答
  •  天涯浪人
    2021-01-12 22:57

    In the latest version of dplyr you can simplify that down to this:

    diamonds %>% count(clarity, cut)
    

    Or if you want to keep the column name 'nrow':

    diamonds %>% count(clarity, cut) %>% rename(nrow = n)
    

    If you've got plyr or rename loaded in your environment then you might need to prefix the rename:

    diamonds %>% count(clarity, cut) %>% dplyr::rename(nrow = n)
    

提交回复
热议问题