quick/elegant way to construct mean/variance summary table

后端 未结 8 2002
甜味超标
甜味超标 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:26

    (I voted for Joshua's.) Here's an Hmisc::summary.formula solution. The advantage of this for me is that it is well integrated with the Hmisc::latex output "channel".

    summary(y ~ interaction(f3,f2,f1), data=d, method="response", 
                        fun=function(y) c(mean.y=mean(y) ,var.y=var(y) ))
    #-----output----------
    y    N=108
    
    +-----------------------+-------+---+---------+-----------+
    |                       |       |N  |mean.y   |var.y      |
    +-----------------------+-------+---+---------+-----------+
    |interaction(f3, f2, f1)|I.a.A  |  4|0.6502307|0.095379578|
    |                       |II.a.A |  4|0.4876630|0.110796695|
    

    snipped output to show the latex -> PDF -> png output:

    enter image description here

提交回复
热议问题