簡體   English   中英

R Stargazer 分離柱帶垂直線

[英]R Stargazer separate columns with vertical line

我想在觀星者回歸表中分開兩列。 到目前為止,我還沒有找到合適的解決方案。 因此,我在這里寫下我的問題。

以下是創建包含 2 列的 stargazer 表的示例代碼:

mod <- lm(data=iris,Sepal.Length~Species)
mod1 <- lm(data=iris,Sepal.Length~Petal.Width+Species)

stargazer(mod,mod1, type = "latex")

RMarkdown 給了我這個 output:

在此處輸入圖像描述

但我想用一行分隔兩列: 在此處輸入圖像描述

誰能幫我解決這個問題?

我假設您必須使用 latex 代碼來更改 output。 我沒有在 Stargazer 選項中找到任何可能性。

提前致謝!

一個提議:

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 output:

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 = "latex"))
mod1_sg <- sub("lcc", "lc|c", mod1_sg)
writeLines(mod1_sg)

在此處輸入圖像描述

問候,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM