group_stat function implementing column names

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"))

library(tidyverse)
library(rlang)

grouped_stats <- function(data, group_vars, summary_vars) {
  data %>%
    group_by(across({{ group_vars }})) %>%
    summarise(across({{ summary_vars }},list(min=min,
                                             median=median,
                                             max=max)))
}

grouped_stats(mtcars, c(cyl,am), c(mpg,hp))
grouped_stats(mtcars, c("cyl","am"), c("mpg","hp"))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.