I want to create a summary statistics table for some summary functions for multiple variables. I've managed to do it using summarise and across, but I get a wide dataframe which is hard to read. Is there a better alternative (perhaps using purrr), or is there an easy way of reshaping the data?
Here is a reproducible example (the funs list contains additional functions I've created myself):
data <- as.data.frame(cbind(estimator1 = rnorm(3),
estimator2 = runif(3)))
funs <- list(mean = mean, median = median)
If I use summarise and across I obtain:
estimator1_mean estimator1_median estimator2_mean estimator2_median
0.9506083 1.138536 0.5789924 0.7598719
What I would like to obtain is:
estimator1 estimator2
mean 0.9506083 0.5789924
median 1.138536 0.7598719
tidyr::pivot_longer(df, everything(), names_sep = "_", names_to = c(".value", "metric"))aftersummarise/across