我想在 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.xtable
的 add.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/