我使用texreg从R创建一个LaTeX表。我想在输出中插入一个空列(出于样式原因)。当然,我可以手动完成此操作,但如果能够自动创建它就太好了。下面是一个示例:
library(texreg)
x1 <- rnorm(n=100,m=1,s=1)
x2 <- rnorm(n=100,m=1,s=1)
e <- rnorm(n=100,m=0,s=1)
y <- 0.1 + 0.3 * x1 + 0.4 * x2 + e
reg1 <- lm(y~x1)
reg2 <- lm(y~x2)
reg3 <- lm(y~x1+x2)
texreg(list(reg1,reg2,reg3)
,stars=c(0.01,0.05,0.1)
,digits=2
,dcolumn=T
,use.packages=F
,file="tabfile.tex")这给出了输出:
\begin{table}
\begin{center}
\begin{tabular}{l D{.}{.}{3.5} D{.}{.}{3.5} D{.}{.}{3.5} }
\hline
& \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} & \multicolumn{1}{c}{Model 3} \\
\hline
(Intercept) & 0.59^{***} & 0.53^{***} & 0.05 \\
& (0.16) & (0.16) & (0.19) \\
x1 & 0.36^{***} & & 0.40^{***} \\
& (0.11) & & (0.10) \\
x2 & & 0.43^{***} & 0.48^{***} \\
& & (0.11) & (0.11) \\
\hline
R$^2$ & 0.10 & 0.13 & 0.25 \\
Adj. R$^2$ & 0.09 & 0.12 & 0.23 \\
Num. obs. & 100 & 100 & 100 \\
RMSE & 1.05 & 1.03 & 0.96 \\
\hline
\multicolumn{4}{l}{\scriptsize{$^{***}p<0.01$, $^{**}p<0.05$, $^*p<0.1$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}我想要的是:
\begin{table}
\begin{center}
\begin{tabular}{lc D{.}{.}{3.5} D{.}{.}{3.5} D{.}{.}{3.5} }
\hline
&& \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} & \multicolumn{1}{c}{Model 3} \\
\hline
(Intercept) && 0.59^{***} & 0.53^{***} & 0.05 \\
&& (0.16) & (0.16) & (0.19) \\
x1 && 0.36^{***} & & 0.40^{***} \\
&& (0.11) & & (0.10) \\
x2 && & 0.43^{***} & 0.48^{***} \\
&& & (0.11) & (0.11) \\
\hline
R$^2$ && 0.10 & 0.13 & 0.25 \\
Adj. R$^2$ && 0.09 & 0.12 & 0.23 \\
Num. obs. && 100 & 100 & 100 \\
RMSE && 1.05 & 1.03 & 0.96 \\
\hline
\multicolumn{5}{l}{\scriptsize{$^{***}p<0.01$, $^{**}p<0.05$, $^*p<0.1$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}当然,如果有一种方法可以插入任意空列,那就更好了。
发布于 2016-08-30 18:57:55
可以使用texreg的custom.columns参数插入新列。新列应该以命名列表的形式提交。custom.col.pos参数可用于指示列的位置。例如,您可以通过添加参数custom.columns = list("new column" = rep("", 3))来插入一个新的空列。
https://stackoverflow.com/questions/39214657
复制相似问题