Created
September 17, 2021 14:50
-
-
Save HorridTom/669eb52b06dbd23433aff02dd5711ecb to your computer and use it in GitHub Desktop.
Examples of multiple summaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# Examples of multiple summaries... | |
# Based on examples here: https://dplyr.tidyverse.org/reference/across.html | |
# one summary across multiple columns | |
mtcars %>% | |
group_by(cyl) %>% | |
summarise(across(where(is.numeric), mean)) | |
# multiple summaries across multiple columns | |
mtcars %>% | |
group_by(cyl) %>% | |
summarise(across(where(is.numeric), | |
list(mean = mean, min = min, max = max))) | |
# with arugments to summary functions | |
mtcars %>% | |
group_by(cyl) %>% | |
summarise(across(where(is.numeric), | |
list(mean = ~ mean(.x, na.rm = TRUE), | |
min = ~ min(.x. na.rm = TRUE), | |
max = ~ max(.x, na.rm = TRUE)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment