【问题标题】:Is it possible to pipe directly into stargazer?可以直接用管道连接到stargazer吗?
【发布时间】:2021-02-09 09:21:06
【问题描述】:

是否可以直接通过管道进入 stargazer,而不是使用下面更复杂的方式?

例子:

date %>%
  filter(x1== "yes",
         x2 == "no") %>% 
  select(x5,
         x6) -> df
  
cols <- c("x5", "x6") 

stargazer(
    df[, cols], type = "text", 
    summary.stat = c("min", "p25", "mean", "p75", "max", "median", "sd", "n") 
)

【问题讨论】:

  • df[, cols] %&gt;% stargazer(type = "text", ...)

标签: r pipe stargazer


【解决方案1】:

是的,您应该可以直接将select 的结果通过管道传输到stargazer

library(dplyr)
library(stargazer)

mtcars %>%
  filter(cyl == 6) %>%
  select(wt, disp, cyl) %>%
  stargazer(type = "text", 
            summary.stat = c("min", "p25", "mean", "p75", "max", "median", "sd", "n"))

=================================================================
Statistic  Min  Pctl(25)  Mean   Pctl(75)  Max  Median St. Dev. N
-----------------------------------------------------------------
wt        2.620  2.822    3.117   3.440   3.460 3.215   0.356   7
disp       145    160    183.314  196.3    258  167.6   41.562  7
cyl         6      6      6.000     6       6     6     0.000   7
-----------------------------------------------------------------

【讨论】:

    【解决方案2】:

    我们可以使用

    library(dplyr)
    library(stargazer)
    df %>%
        select(all_of(cols)) %>%
        stargazer(type = "text", 
            summary.stat = c("min", "p25", "mean", "p75", "max", "median", "sd", "n"))
    

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2015-02-08
      • 1970-01-01
      • 2015-05-16
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      相关资源
      最近更新 更多