简体   繁体   中英

How to get a clean descriptive statistics table that displays all variables grouped by outcomes of a categorical variable?

The categorical variable I'm using has four possible outcomes (ResJobLocationChoice). I want to find the n observations, mean, standard deviation, and min/max for each outcome using multiple variables (categorical and continuous). Preferably in 1 table.

I've tried but I haven't been able to get it working with multiple variables.

with(data_df, table(Female, ResJobLocationChoice))
with(data_df, do.call(rbind, tapply(Wage, ResJobLocationChoice, function(x) c(Mean = mean(x), St.Dev. = sd(x)))))

I also tried using stargazer, but to no success:

data_df %>% 
  group_by(ResJobLocationChoice) %>% 
  stargazer(data_df[c("Wage","CommuteTime", "HousingPrice")], type="text", 
            digits=2, title="Residential-Job Location Choice")

As there is no replication data available have used population data inbuilt in R. Create the table with summary stats and then use stargazer with summary = FALSE

population %>% 
  group_by(country) %>% 
  summarise(amean=round(mean(population),2),
            asd=round(sd(population),2)) %>% 
stargazer(type = "text", summary=FALSE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM