R:xtable 标题(或评论)

标签 r xtable

我想在 xtable. 打印出来的表格下面放一条评论我认为最好的选择是使用“标题”选项:xtable(tablename, caption="This is a caption") .但这以某种方式自动放入“表 1”,因此输出如下所示:

Table 1: This is a caption.



有什么方法可以抑制这种或任何更简单的方法来简单地将评论作为表格中的附加最后一行?

最佳答案

首先,一些模拟数据:

x <- sample(LETTERS, 5, replace = TRUE)
y <- sample(LETTERS, 5, replace = TRUE)
z <- table(x, y)

现在这里有一个有点笨拙的解决方案,使用 print.xtableadd.to.row争论。
comment          <- list()
comment$pos      <- list()
comment$pos[[1]] <- c(nrow(z))
comment$command  <- c(paste("\\hline \n",  # we`ll replace all default hlines with this and the ones below
                            "your footnote, caption or whatever.  \n",
                            sep = ""))
print(xtable(z),
      add.to.row = comment,
      hline.after = c(-1, 0))  # indicates rows that will contain hlines (the last one was defined up there)

如果您希望将评论放在数据之前,请使用 comment$pos[[1]] <- c(0)而不是 comment$pos[[1]] <- c(nrow(z))并调整 hline.after因此。

这是我的输出:
% latex table generated in R 2.14.1 by xtable 1.7-0 package
% Mon Feb 20 02:17:58 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrr}
\hline
& B & C & P & V \\ 
\hline
A &   0 &   0 &   0 &   1 \\ 
D &   1 &   0 &   0 &   0 \\ 
I &   0 &   0 &   0 &   1 \\ 
P &   0 &   0 &   1 &   0 \\ 
Z &   0 &   1 &   0 &   0 \\ 
\hline
your footnote, caption or whatever.  
\end{tabular}
\end{center}
\end{table}

关于R:xtable 标题(或评论),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6163823/

相关文章:

R:引用类类型的引用类中的字段

r - 按一天中的时间子集 xts 对象

r - 指数平滑法

r - 使用 xtable 对 latex 输出表进行排序

R、knitr、xtable、交替行颜色

r - 在跨设备和平台(尤其是PDF)的R图形中使用Unicode 'dingbat-like'字形

performance - 在 R 中交叉制表两个大量逻辑向量的最快方法

在 RMarkdown 中使用 Tufte_handout 旋转 xtable 列名

使用带有 longtable 选项的 xtable 时重复标题

r - xtable:更改颜色和厚度(table.attributes)