quick/elegant way to construct mean/variance summary table

后端 未结 8 2020
甜味超标
甜味超标 2020-12-13 19:45

I can achieve this task, but I feel like there must be a \"best\" (slickest, most compact, clearest-code, fastest?) way of doing it and have not figured it out so far ...

8条回答
  •  臣服心动
    2020-12-13 20:14

    @joran is spot-on with the ddply answer. Here's how I would do it with aggregate. Note that I avoid the formula interface (it is slower).

    aggregate(d$y, d[,c("f1","f2","f3")], FUN=function(x) c(mean=mean(x),var=var(x)))
    

提交回复
热议问题