不幸的是,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"))