Created
February 12, 2018 10:13
-
-
Save privefl/34b50f4e5422e0d7526f42abe87f2cdf 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