I am following the instructions laid out here to create a clean table of summary statistics.
In these instructions, the input to the summary_table() function is a list of lists, as shown here:
our_summary1 <-
list("Miles Per Gallon" =
list("min" = ~ min(.data$mpg),
"max" = ~ max(.data$mpg),
"mean (sd)" = ~ qwraps2::mean_sd(.data$mpg)),
"Displacement" =
list("min" = ~ min(.data$disp),
"median" = ~ median(.data$disp),
"max" = ~ max(.data$disp),
"mean (sd)" = ~ qwraps2::mean_sd(.data$disp)),
"Weight (1000 lbs)" =
list("min" = ~ min(.data$wt),
"max" = ~ max(.data$wt),
"mean (sd)" = ~ qwraps2::mean_sd(.data$wt)),
"Forward Gears" =
list("Three" = ~ qwraps2::n_perc0(.data$gear == 3),
"Four" = ~ qwraps2::n_perc0(.data$gear == 4),
"Five" = ~ qwraps2::n_perc0(.data$gear == 5))
)
I have 48 variables in my dataset, and each variable has its own column. Is there a cleaner way for me to cycle through all the columns in my dataframe to create an object like the one above without typing it out manually like this? I would ideally prefer a solution using the tidyverse.
One thing I was considering doing was changing my data to long format, then using group_by() to group by each of the columns from the original data, then using summarise(). However, my understanding is that this would yield a single list, not a list of lists like is necessary for summary_table().
If there is a completely different way of creating a summary table than what I am trying to do here, please let me know. This one looked the neatest of the options I was considering. For each variable, I'd like to be able to rename it and include the minimum value, maximum value, mean, and standard deviation.