【问题标题】:How to align coefficients using stargazer in R Markdown?如何在 R Markdown 中使用 stargazer 对齐系数?
【发布时间】:2017-02-03 22:46:12
【问题描述】:

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

这是我的“块代码”

```{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"))
```

【问题讨论】:

    标签: r-markdown stargazer


    【解决方案1】:

    align=TRUE 开头的tex表

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

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

    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 太高了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-20
      • 2016-10-03
      • 2016-05-06
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      相关资源
      最近更新 更多