Skip to content

Instantly share code, notes, and snippets.

@privefl
Created February 12, 2018 10:13
Show Gist options
  • Save privefl/34b50f4e5422e0d7526f42abe87f2cdf to your computer and use it in GitHub Desktop.
Save privefl/34b50f4e5422e0d7526f42abe87f2cdf 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