与其使用循环,不如考虑将现有print.xtable
功能与粘贴结合使用。
hdashlines: 考虑使用print.xtable
参数。例如,有一个参数hline.after
控制表格行之间的水平线。
vspace:这可能更简单,使用paste
.
例如:
library(xtable)
df <- data.frame(name=rep(letters[1:3],each=24),salary=runif(24*3,100,200))
lst <- tapply(df$salary,df$name,matrix,nrow=4,byrow=T)
xlst <- lapply(lst,function(x)print(xtable(x), hline.after=1:nrow(x)))
xlst <- lapply(xlst, paste, "\\vspace{2em}")
xlst
[1] "%latex table 在 R 2.13.1 中由 xtable 1.5-6 包生成\n% Tue Aug 23 13:36:41 2011\n\begin{table}[ht]\n\begin{center}\n \begin{tabular}{rrrrrrr}\n & 1 & 2 & 3 & 4 & 5 & 6 \\ \n 1 & 158.66 & 115.81 & 106.70 & 128.78 & 157.43 & 191.01 \\\n \hline\n2 & 159.09 & 172.31&153.93&127.91&106.93&147.95 \\ \ \ \ n \ hline \ n3&135.65&135.65&139.45&192.90&108.78&108.78&186.52&164.10 \ \n
\hline\n\end{表格}\n\end{center}\n\end{table}\n \vspace{2em}"
有关?print.xtable
更多详细信息,请参阅。如果hline.after
对于您的目的不够灵活,那么看看add.to.row
您可以在哪里指定要添加的位置和确切的元素类型。