我想在xtable输出中标注尺寸.但是,xtable即使我手动指定它们,表方法也不会输出维度标签table:
set.seed(10)
d <- data.frame(x=sample(1:4),y=sample(1:4))
tb <- with(d, table(d,dnn=c("Xs","Ys")))
> tb
Ys
Xs 1 2 3 4
1 0 0 0 1
2 0 1 0 0
3 1 0 0 0
4 0 0 1 0
> xtable(tb)
% latex table generated in R 2.15.1 by xtable 1.7-0 package
% Tue Oct 9 09:06:10 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrr}
\hline
& 1 & 2 & 3 & 4 \\
\hline
1 & 0 & 0 & 0 & 1 \\
2 & 0 & 1 & 0 & 0 \\
3 & 1 & 0 & 0 & 0 \\
4 & 0 & 0 & 1 & 0 \\
\hline
\end{tabular}
\end{center}
\end{table}
Run Code Online (Sandbox Code Playgroud)
检查代码xtable.table不会产生任何秘密.如果没有使用multirow手动构建它们,是否有任何方法可以标记尺寸?
软件包中的一种解决方案tables:
library(tables)
tblr <- tabular((Xs = as.factor(x)) ~ (Ys = as.factor(y)), data = d)
latex(tblr)
\begin{tabular}{lcccc}
\hline
& \multicolumn{4}{c}{Ys} \\
Xs & 1 & 2 & 3 & \multicolumn{1}{c}{4} \\
\hline
1 & $0$ & $0$ & $0$ & $1$ \\
2 & $0$ & $1$ & $0$ & $0$ \\
3 & $1$ & $0$ & $0$ & $0$ \\
4 & $0$ & $0$ & $1$ & $0$ \\
\hline
\end{tabular}
Run Code Online (Sandbox Code Playgroud)