【发布时间】:2012-03-28 08:08:25
【问题描述】:
在我提问之前让我创建一些数据。
my.data <- data.frame(A = sample(seq(1,100,by=5),10,replace=TRUE),W = rnorm(10),X =sample(1:10),Y = sample(c("yes", "no"), 10, replace = TRUE),Z=sample(c('a','b','c','d'),10,replace=TRUE))
attach(my.data)
my.d <- xtabs(W~Z+Y+A);my.d
table.data <- ftable(my.d)
result1 <- round(table.data,2)
结果 1 看起来像 ..
A 6 11 16 26 71 76 86 91
Z Y
a no 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
yes 0.00 0.56 0.00 0.00 0.00 0.79 0.00 0.01
b no 0.61 0.00 -0.22 0.14 0.00 0.00 -0.08 1.71
yes 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c no 0.00 0.00 0.00 0.00 -0.08 0.00 0.00 0.00
yes 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
d no 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00
yes 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
我实际上正在使用 knitr 包写一篇文章。 有没有办法将 result1 转换为乳胶表 当我的 *.rnw 文件被编译时自动?
我尝试使用 xtable 但出现以下错误...
Error in UseMethod("xtable") : no applicable method for 'xtable' applied to an object of class "ftable"
谢谢@DWin 和@Yihui。除了latex(),我还使用了如下所述的xtable
print(xtable(ftable2data.frame(result1)))
为了删除不必要的行名,我做了以下操作
print(xtable(ftable2data.frame(result1)),include.rownames=FALSE)
【问题讨论】: