Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Last active July 2, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/8d9e2f3f43741ad75b0a44798ce5d937 to your computer and use it in GitHub Desktop.
Save ramnathv/8d9e2f3f43741ad75b0a44798ce5d937 to your computer and use it in GitHub Desktop.
group_mean
#' Group Mean
#'
#' @examples
#' iris %>%
#' group_mean(Species, Petal.Length)
group_mean <- function(tbl, group_var, summary_var){
tbl %>%
group_by({{ group_var }}) %>%
summarize(
{{ summary_var }} := mean({{ summary_var }})
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment