compute means of a group by factor

前端 未结 4 623
太阳男子
太阳男子 2021-01-02 06:49

Is there a way that this can be improved, or done more simply?

means.by<-function(data,INDEX){
  b<-by(data,INDEX,function(d)apply(d,2,mean))
  return(         


        
4条回答
  •  再見小時候
    2021-01-02 07:33

    Does the aggregate function do what you want?

    If not, look at the plyr package, it gives several options for taking things apart, doing computations on the pieces, then putting it back together again.

    You may also be able to do this using the reshape package.

提交回复
热议问题