Generation

generate functionMon, 24 Jul 2023

dplyr::summarise column names that are numbers. Apply sum

summarise_numeric <- function(df, fun) { num_cols <- sapply(df, is.numeric) df[, num_cols] %>% summarise_all(fun) } dplyr::summarise(iris, mean = mean(Sepal.Length), sd = sd(Sepal.Length)) summarise_numeric(iris, mean) summarise_numeric(iris, sd)

Want to kickstart your project?Use the new AI Studio to create your code