r - 将 xtable 输出拆分为子表

标签 r sweave

有一个关于在有多列时将 xtable 与 Sweave 结合使用的问题。我正在处理的表格大约有 25 列和 5 行。确切的列数未知,因为它是动态的。

当我运行时说,

table1 <- table (df$someField)

我得到的表格基本上超出了页面长度。

       ColA    ColB    ColC
---------------------------
RowA   1       2       3   ......
RowB   3       4       6   ......

如果对此执行 xtable,并通过 Sweave 运行它,

xtable(table1, caption="some table")

它溢出了。

我正在寻找的是这样的东西,

       ColA    ColB    ColC
---------------------------
RowA   1       2       3 
RowB   3       4       6 

       ColD    ColE    ColF 
---------------------------
RowA   11       9       34 
RowB   36       8       65  

带有\hline 等标记。基本上,将 xtable 分成多个部分,例如每个“子表”5 列。

我也在批处理作业中运行它,因此我无法对单个文件进行更改,无论它必须能够通过在 Rnw 文件上运行 Sweave 生成​​什么解决方案。

提前致谢,

问候,

  • 拉吉。

最佳答案

以下是来自 taRifx 包中 ?latex.table.by 的示例。您可以在 LaTeX 中使用 longtable 编写类似的内容,并使用 latex.table.by 代码作为原型(prototype)。

my.test.df <- data.frame(grp=rep(c("A","B"),10),data=runif(20))
library(xtable)
latex.table.by(my.test.df)
#   print(latex.table.by(test.df), include.rownames = FALSE, include.colnames = TRUE, sanitize.text.function = force)
#   then add \usepackage{multirow} to the preamble of your LaTeX document
#   for longtable support, add ,tabular.environment='longtable' to the print command (plus add in ,floating=FALSE), then \usepackage{longtable} to the LaTeX preamble

无论如何,LaTeX 中的 longtable 包是关键。

编辑:看来您的列太多,而不是行太多。在这种情况下,首先尝试仅美化该页面。

在标题中:

\usepackage{lscape}

在你的 table 周围:

\begin{landscape}
...
\end{landscape}

或者只使用sidewaystable

如果您的表格太宽而无法容纳一页,请尝试 supertabular 包,从描述来看,它可能会根据宽度处理跨多个页面的情况(但我从未使用过)所以不能确定)。

关于r - 将 xtable 输出拆分为子表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7423423/

相关文章:

r - xtable 周围的空白

R包警告: Files in the 'vignettes' directory newer than all files in 'inst/doc'

regex - 在 Sweave 表达式中查找 R 代码的正则表达式

r - 将 R 代码的输出插入到 Rnw 文件中

r - KableExtra:与\makecell 结合使用时,colortbl's\cellcolor 不会填充整个单元格

r - 如何将 R 数据集中的多列合并为一列?

r - 使用 dplyr 获取相对频率百分比的更智能方法?

R + 组织模式 : how to avoid naming plot files?

r - 如何从 R 中的数据框列中删除所有未指定的指定单词

r - 将 NA 包含为 ddply 的可能子集因子