Created
February 12, 2018 10:12
-
-
Save privefl/3f2e2d8314bb941e9bdf78a137ba434a to your computer and use it in GitHub Desktop.
This file contains hidden or 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