in R, how to calculate mean of all column, by group?

后端 未结 5 1707
挽巷
挽巷 2020-12-18 06:25

I need to get the mean of all columns of a large data set using R, grouped by 2 variables.

Lets try it with mtcars:

library(dplyr)
g_mtcars <- gro         


        
5条回答
  •  独厮守ぢ
    2020-12-18 06:42

    For the sake of completeness you could use package plyr and do this:

    library(plyr)
    ddply(mtcars,c('cyl','gear'), summarize,mean_hp=mean(hp))
    

提交回复
热议问题