我想在我打印的表格下面发表评论,xtable.我认为最好的选择是使用"标题"选项:xtable(tablename, caption="This is a caption").但这是以某种方式自动放入"表1",因此输出如下:
表1:这是一个标题.
是否有任何方法可以抑制这种或任何更简单的方式将注释简单地作为表中的附加最后一行?
Wal*_*cio 14
首先,一些模拟数据:
x <- sample(LETTERS, 5, replace = TRUE)
y <- sample(LETTERS, 5, replace = TRUE)
z <- table(x, y)
Run Code Online (Sandbox Code Playgroud)
现在这是一个有点笨拙的解决方案,使用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)
Run Code Online (Sandbox Code Playgroud)
如果您希望将评论放在数据之前,请使用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}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8437 次 |
| 最近记录: |