Last active
February 12, 2018 10:11
-
-
Save privefl/07bc6d0eced32fcbf27ac6f91d73b948 to your computer and use it in GitHub Desktop.
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(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