How can I use dplyr to apply a function to all non-group_by columns?

后端 未结 2 880
自闭症患者
自闭症患者 2021-02-01 07:15

I\'m trying to use the dplyr package to apply a function to all columns in a data.frame that are not being grouped, which I would do with aggregate():



        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 07:59

    This will get you almost all the way in dplyr.

    h = iris %.%
      group_by(Species) %.%
      do(function(d){
        sapply(Filter(is.numeric, d), mean)  
      })
    
    as.data.frame(h)
    

提交回复
热议问题