dplyr summarise_each with na.rm

后端 未结 5 1797
伪装坚强ぢ
伪装坚强ぢ 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:40

    Following the links in the doc, it seems you can use funs(mean(., na.rm = TRUE)):

    library(dplyr)
    by_species <- iris %>% group_by(Species)
    by_species %>% summarise_each(funs(mean(., na.rm = TRUE)))
    

提交回复
热议问题