在“表格"包中:如何获取变量子集的列百分比? [英] In the "Tables"-package: How to get column percentages of a subset of a variable?
本文介绍了在“表格"包中:如何获取变量子集的列百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在名为"Percent"的列下面的表中,显示了总列百分比.如何获得它以显示"vs"的每个级别中"am"的每个级别的列百分比?
In the table below the column named "Percent" shows the total column percent. How do I get it to show the column percent of each level of "am" within each level of "vs"?
这就是我所拥有的:
这就是我想要的:
下面的针织大块
<<echo=FALSE,results='asis'>>=
#
# library(tables)
# library(Hmisc)
# library(Formula)
## This gives me column percentages for the total table.
latex( tabular( Factor(vs)*Factor(am) ~ gear*Percent("col"), data=mtcars ) )
## I am trying to get column percentages for each level of "vs"
@
推荐答案
对于denom选项,您可以使用Equal()
伪函数来计算因子对分母的水平.
You can use the Equal()
pseudofunction for the denom option to make levels of factor vs the denominator.
tabular( Factor(vs)*Factor(am) ~ gear*Percent(denom = Equal(vs)), data=mtcars)
gear
vs am Percent
0 0 66.67
1 33.33
1 0 50.00
1 50.00
这篇关于在“表格"包中:如何获取变量子集的列百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文