如何在 R Markdown 中使用 stargazer 对齐系数? [英] How to align coefficients using stargazer in R Markdown?

查看:100
本文介绍了如何在 R Markdown 中使用 stargazer 对齐系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我添加 align=TRUE 时,文档都不会编织.我想对齐每一列的系数,以便它们的小数直接在彼此之上/之下.

Every time I add align=TRUE the document won't knit. I would like to align each column's coefficients so that their decimals are directly above/below each other.

这是我的块代码"

```{r, results="asis", echo="FALSE", eval="TRUE"}
library(stargazer)
stargazer(model1, model2, model3, type = "latex",  
          title = "Country Deaths from Political Violence in 1975",
          dep.var.labels.include = FALSE, dep.var.caption = "Deaths",
          digits = 1, header = FALSE,
          covariate.labels = c("Intercept", "Sanctions", "Political Rights", 
                               "Upper 20 percent income share", 
                               "Interaction of Political Rights and Sanctions"))
```

推荐答案

使用 align=TRUE 生成的 tex 表以

The tex tables produced with align=TRUE begin with

\begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} } 

在 stargazer 上应用 gsub 并将点替换为 \\cdot.然后使用cat,为我解决了这个问题.

Applying gsub on stargazer and replacing the dots with \\cdot. Then using cat, solved the problem for me.

MWE:

table<-stargazer(example, align=TRUE)
tablenew<-gsub("D{.}{.}{-3} ","D.{\\cdot}{-3}",table,fixed=TRUE)

<<label, eval=TRUE, echo=FALSE, results='asis', warning=FALSE, message=FALSE>>=
knitrout<-cat(tablenwe, sep="\n")
@

一个缺点是 \cdot 太高了.

One drawback is that \cdot is too high.

这篇关于如何在 R Markdown 中使用 stargazer 对齐系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆