Created
August 16, 2019 19:57
-
-
Save dgkeyes/fec4273eedc7a6e0771d3adfefcd9a32 to your computer and use it in GitHub Desktop.
summarize with totals
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
dk_summarize_with_totals <- function(.data, group_by_var, mean_var){ | |
groups_summary <- .data %>% | |
dplyr::group_by({{ group_by_var }}) %>% | |
dplyr::summarize(mean = mean({{ mean_var }})) %>% | |
dplyr::rename("group" = {{ group_by_var }} ) | |
overall_summary <-.data %>% | |
dplyr::summarize(mean = mean({{ mean_var }})) %>% | |
dplyr::mutate(group = "Total") | |
dplyr::bind_rows(groups_summary, | |
overall_summary) | |
} | |
dk_summarize_with_totals(iris, Species, Sepal.Length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment