【问题标题】:stargazer summary.stat relabel column headingsstargazer summary.stat 重新标记列标题
【发布时间】:2016-05-24 10:48:19
【问题描述】:

是否可以在 stargazer 中重新标记 summary.stats 的列标题?默认标签似乎忽略了我的首选标签。提前致谢!

library(stargazer)
stargazer(attitude, 
           column.labels = c("Obs", "P25", "P50", "P75"),
           summary.stat = c("n", "p25", "median", "P75")
)

【问题讨论】:

    标签: r labels summary stargazer


    【解决方案1】:

    不幸的是,column.labels 命令仅适用于使用 stargazer 创建的回归表。但是,由于 stargazer 也可以直接输出数据帧,因此您可以创建自己的数据帧,其中包含所需的摘要统计信息以及您希望它们具有的名称,如下所示:

    library(stargazer)
    # create data frame first, set nrow to number of your variables
    dfdescriptives <- data.frame(matrix(nrow = 3, ncol = 0))
    
    # specify the variables you want to summarize here
    vars <- attitude[, c("var1","var5","id")]
    
    # assign inteligible variable names as rownames
    row.names(dfdescriptives) <- c("Variable 1", "Variable 5", "ID Variable")
    
    # get number of observations for each variable
    dfdescriptives$Obs <- apply(vars, 2, function(x) sum(complete.cases(x)))
    # get 25th percentile for each variable
    dfdescriptives$P25 <- apply(vars, 2, function(x) summary(x)[[2]])
    # get median for each variable
    dfdescriptives$P50 <- apply(vars, 2, function(x) summary(x)[[3]])
    # get 75th percentile for each variable
    dfdescriptives$P75 <- apply(vars, 2, function(x) summary(x)[[5]])
    
    # output dataframe directly w/o summary
    stargazer(dfdescfull, summary = FALSE, header = FALSE, 
          title = "Descriptive Statistics as I would like to call them.",
          notes = c("Source: stackoverflow.com"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 2021-09-07
      • 1970-01-01
      • 2014-06-14
      • 2018-08-04
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多