我怎样才能使用Hmisc
'slatex
来获得像......
Group 1 Group 2
d n beta Sub-group 1 Sub-group 2 Sub-group 1 Sub-group 2
10 100 0.25 1 9
0.75 2
500 0.25 3 10
0.75 4 11 ... ...
100 100 0.25 5 12
0.75 6 13
500 0.25 7 ...
0.75 8
...?以下是我到目前为止所拥有的。不知何故,我想告诉latex
使用前三列来显示行标签。此外,NA 不会被删除。
x <- matrix(1:72, ncol=4, nrow=8) # data part
colnames(x) <- c("gr1.sgr1", "gr1.sgr2", "gr2.sgr1", "gr2.sgr2")
rmNames <- function(x) {x[c(FALSE, x[-1]==x[-length(x)])] <- ""; x}
rn <- apply(expand.grid(beta=c(0.25, 0.75), n=c(100, 500), d=c(10, 100))[, 3:1], 2, rmNames)
x <- cbind(rn, x)
x[2,5] <- NA
require(Hmisc)
latex(x,
file="",
cgroup=c("", "Group 1", "Group 2"),
n.cgroup=c(3, 2, 2),
na.blank=TRUE,
rowlabel=c("d", "n", "beta"),
booktabs=TRUE,
collabel.just=rep("c", 2))
更新
使用 joran 的方法,我得到(所以添加rownames=NULL
and rep("c",7)
):
\begin{table}[!tbp]
\begin{center}
\begin{tabular}{lllcllcll}
\toprule
\multicolumn{3}{c}{\bfseries }&
\multicolumn{1}{c}{\bfseries }&
\multicolumn{2}{c}{\bfseries Group 1}&
\multicolumn{1}{c}{\bfseries }&
\multicolumn{2}{c}{\bfseries Group 2}
\tabularnewline
\cline{1-9}
\multicolumn{1}{c}{d}&\multicolumn{1}{c}{n}&\multicolumn{1}{c}{beta}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{gr1.sgr1}&\multicolumn{1}{c}{gr1.sgr2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{gr2.sgr1}&\multicolumn{1}{c}{gr2.sgr2}\tabularnewline
\midrule
10&100&0.25&&1&9&&17&25\tabularnewline
&&0.75&&2&NA&&18&26\tabularnewline
&500&0.25&&3&11&&19&27\tabularnewline
&&0.75&&4&12&&20&28\tabularnewline
100&100&0.25&&5&13&&21&29\tabularnewline
&&0.75&&6&14&&22&30\tabularnewline
&500&0.25&&7&15&&23&31\tabularnewline
&&0.75&&8&16&&24&32\tabularnewline
\bottomrule
\end{tabular}
\end{center}
\end{table}
1) 为什么要插入空列 ( \multicolumn{1}{c}{}
)?
2) 为什么NA
s 没有被替换?