2
我期待为三个主要效应构建一个应变表。这些都是犯罪,性别和先前的信念。响应变量是否是一个宽松的句子被授予。R中的三因子应变表
这是迄今为止我所见过的最好的。
Crime Gender Priorconv Yes No
1 Shoplifting Men N 24 1
2 Other Theft Acts Men N 52 9
3 Shoplifting Women N 48 3
4 Other Theft Acts Women N 22 2
5 Shoplifting Men P 17 6
6 Other Theft Acts Men P 60 34
7 Shoplifting Women P 15 6
8 Other Theft Acts Women P 4 3
这是由下面的代码
table1<-expand.grid(Crime=factor(c("Shoplifting","Other Theft Acts")),Gender=factor(c("Men","Women")),
Priorconv=factor(c("N","P")))
table1<-data.frame(table1,Yes=c(24,52,48,22,17,60,15,4),No=c(1,9,3,2,6,34,6,3))
创建不幸的是,这是不是很优雅,所以我想知道是否有另一种方式来更清晰地呈现数据。
谢谢。
也许看看'xtabs'和/或' ftable' – 2014-11-04 21:56:33
@DominicComtois我喜欢xtabs的功能。我尝试使用xtabs(cbind(是,否)〜Crime + Gender + Priorconv,data = table1) – JohnK 2014-11-04 22:16:08
很高兴知道!也许你可以发布代码和输出作为你自己问题的答案。我相信这对你情况下的其他人会有用。 – 2014-11-04 22:27:04