我正在尝试使用Hmisc
获取this file的百分比交叉表。但是为什么summary()
从变量OCCUPATION中删除一个类别(“OTHERS”)?
library(Hmisc)
summary(ID ~ OCCUPATION, data=df, method="reverse")
输出: ID描述性统计
+--------------------------+--------+--------+
| |HUSBAND |SELF |
| |(N=28) |(N=72) |
+--------------------------+--------+--------+
|OCCUPATION : SELF EMPLOYED|93% (26)|31% (22)|
+--------------------------+--------+--------+
将此与简单的table()
OCCUPATION
ID OTHERS SELF EMPLOYED
HUSBAND 2 26
SELF 50 22
答案 0 :(得分:4)
这是为了任何遇到这个特殊问题的人的利益。在查看Hmisc
的非常长的文档后,我偶然发现了解决方案。解决方案是将print()
与exclude1=F
选项一起使用:
print(summary(ID ~ OCCUPATION, data=df, method="reverse"), exclude1=F)
Descriptive Statistics by ID
+-------------------+--------+--------+
| |HUSBAND |SELF |
| |(N=28) |(N=72) |
+-------------------+--------+--------+
|OCCUPATION : OTHERS| 7% ( 2)|69% (50)|
+-------------------+--------+--------+
| SELF EMPLOYED |93% (26)|31% (22)|
+-------------------+--------+--------+