2016-05-24 19 views
1

是否可以在stargazer中重新標記summary.stats的列標題?默認標籤似乎忽略了我的首選標籤。提前致謝!stargazer summary.stat relabel列標題

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

回答

0

不幸的是,column.labels命令僅適用於使用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"))