我正在尝试在 R 中生成一个简单的交叉表,并使用 Rstudio 中的 knitr 将其导出到乳胶。
我希望该表看起来像一个可发布的表,其中包含列中变量的每个类别的行标题、列标题和子标题。由于我的表格具有相同的行和列类别,我希望用数字替换列级标题。请参见下面的示例:
Profession Mother
ProfesssionFather 1. 2. 3.
1. Bla frequency frequency frequency
2. blahabblab
3. blahblahblah
我正在接近'xtable'(我无法打印行和列标题,而不是多列标题)和'tables'包(我不能用数字替换列类别)。
最小的例子:
work1 <- paste("LongString", 1:10, sep="")
work2 <- paste("LongString", 1:10, sep="")
t <- table(work1, work2) # making table
t # table with repated row/column names
colnames(t) <- paste(1:10, ".", sep="") # replacing column names with numeric values
xtable(t) # headers are omitted for both rows and columns
work <- data.frame(cbind(work1, work2)) # prepare for use of tabular
tabular((FathersProfession=work1) ~ (MothersProfession=work2), data=work) # have headers, but no way to change column categories from "LongString"x to numeric.