首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >texreg -创建空列

texreg -创建空列
EN

Stack Overflow用户
提问于 2016-08-30 04:27:17
回答 1查看 766关注 0票数 0

我使用texreg从R创建一个LaTeX表。我想在输出中插入一个空列(出于样式原因)。当然,我可以手动完成此操作,但如果能够自动创建它就太好了。下面是一个示例:

代码语言:javascript
复制
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")

这给出了输出:

代码语言:javascript
复制
\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}

我想要的是:

代码语言:javascript
复制
\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}

当然,如果有一种方法可以插入任意空列,那就更好了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-30 18:57:55

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39214657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档