0

我使用 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}

如果有办法插入任意空列,那当然会更好。

4

1 回答 1

2

custom.columns您可以使用 的参数插入新列texreg。新列应作为命名列表移交。该custom.col.pos参数可用于指示列应位于的位置。例如,您可以通过添加参数来插入一个新的空列custom.columns = list("new column" = rep("", 3))

于 2016-08-30T10:57:54.563 回答