Created
February 8, 2017 22:31
-
-
Save sdtaylor/40e95fa8fa32e5dd7c8989d087e450d4 to your computer and use it in GitHub Desktop.
Use dplyr inside a function with arbitray column names
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
#Use dplyr inside a function with arbitray column names | |
#The dots stuff is from the internal workings of dplyr | |
#Don't forget the _ at the end of the group by. | |
#Other function also have the _ variation with the .dots argument available, | |
#but when I first made this in early 2016 not all of them did. | |
my_function=function(original_df, variables){ | |
dots=lapply(variables, as.symbol) | |
summarized_data = original_data %>% | |
group_by_(.dots = dots ) %>% | |
summarize(freq=sum(freq)) %>% | |
ungroup() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment