Skip to content

Instantly share code, notes, and snippets.

@privefl
Last active February 12, 2018 10:11
Show Gist options
  • Save privefl/07bc6d0eced32fcbf27ac6f91d73b948 to your computer and use it in GitHub Desktop.
Save privefl/07bc6d0eced32fcbf27ac6f91d73b948 to your computer and use it in GitHub Desktop.
library(dplyr)
# dplyr programming
my_summarise <- function(df, group) {
group <- enquo(group)
df %>%
group_by(!!group) %>%
summarise_all(mean)
}
my_summarise(iris, Species)
# macros
my_summarise2 <- gtools::defmacro(df, group, expr = {
df %>%
group_by(group) %>%
summarise_all(mean)
})
my_summarise2(iris, Species)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment