Hey, I have written the following functions but I want to change the names of the columns so that it says var_min, var_median and var_max respectively. I have tried a lot but can't manage to implement this, could someone help me? Thank you!
library(tidyverse)
library(rlang)
grouped_stats <- function(data, group_vars, summary_vars) {
data %>%
group_by(across({{ group_vars }})) %>%
summarise(across({{ summary_vars }},c(min,median,max)))
}
grouped_stats(mtcars, c(cyl,am), c(mpg,hp))
grouped_stats2 <- function(data, group_vars, summary_vars) {
data %>%
group_by(across(all_of(group_vars))) %>%
summarise(across(all_of(summary_vars), list(min,median,max)))
}
grouped_stats2(mtcars, c("cyl","am"), c("mpg","hp"))