dplyr summarise_each with na.rm

后端 未结 5 1811
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 18:41

Is there a way to instruct dplyr to use summarise_each with na.rm=TRUE? I would like to take the mean of variables with summaris

5条回答
  •  孤街浪徒
    2020-12-12 19:22

    Take for instance mtcars data set

    library(dplyr)
    

    You can always use summarise to avoid long syntax:

    mtcars %>%
      group_by(cyl) %>% 
      summarise(mean_mpg = mean(mpg, na.rm=T),
                sd_mpg = sd(mpg, na.rm = T))
    

提交回复
热议问题