# NOT RUN {
# across() -----------------------------------------------------------------
iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), mean))
iris %>%
mutate(across(where(is.factor), as.character))
# Additional parameters can be passed to functions
iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), mean, na.rm = TRUE))
# A named list of functions
iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), list(mean = mean, sd = sd)))
# Use the .names argument to control the output names
iris %>%
group_by(Species) %>%
summarise(
across(starts_with("Sepal"),
mean,
.names = c("mean_sepal_length", "mean_sepal_width"))
)
# }
Run the code above in your browser using DataLab