如何解决R Stargazer 用垂直线分隔列
我想在观星者回归表中分开两列。 到目前为止,我还没有找到合适的解决方案。因此,我在这里写下我的问题。
mod <- lm(data=iris,Sepal.Length~Species)
mod1 <- lm(data=iris,Sepal.Length~Petal.Width+Species)
stargazer(mod,mod1,type = "latex")
RMarkdown 给了我这个输出:
有人能帮我解决这个问题吗?
我假设您必须使用乳胶代码来更改输出。我在观星者选项中没有发现任何可能性。
提前致谢!
解决方法
一个命题:
mod <- lm(data=iris,Sepal.Length~Species)
mod1 <- lm(data=iris,Sepal.Length~Petal.Width+Species)
mod1_sg <- capture.output(stargazer::stargazer(mod,mod1,type = "text"))
library(stringr)
mod1_sg[6:25] <- paste(str_sub(mod1_sg[6:25],1,44),str_sub(mod1_sg[6:25],46,68),sep="|")
mod1_df <- setNames(as.data.frame(noquote(mod1_sg)[-1]),"")
print(mod1_df,row.names=FALSE)
#>
#> ====================================================================
#> Dependent variable:
#> ------------------------------------------------
#> Sepal.Length
#> (1) | (2)
#> --------------------------------------------|-----------------------
#> Petal.Width | 0.917***
#> | (0.194)
#> |
#> Speciesversicolor 0.930*** | -0.060
#> (0.103) | (0.230)
#> |
#> Speciesvirginica 1.582*** | -0.050
#> (0.103) | (0.358)
#> |
#> Constant 5.006*** | 4.780***
#> (0.073) | (0.083)
#> |
#> --------------------------------------------|-----------------------
#> Observations 150 | 150
#> R2 0.619 | 0.669
#> Adjusted R2 0.614 | 0.663
#> Residual Std. Error 0.515 (df = 147) | 0.481 (df = 146)
#> F Statistic 119.265*** (df = 2; 147)|98.525*** (df = 3; 146)
#> ====================================================================
#> Note: *p<0.1; **p<0.05; ***p<0.01
# Created on 2021-02-15 by the reprex package (v0.3.0.9001)
更新
对于 LaTeX 输出:
mod <- lm(data=iris,type = "latex"))
mod1_sg <- sub("lcc","lc|c",mod1_sg)
writeLines(mod1_sg)
问候,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。