Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. example <- function(df, column_name, input_vec) {
  2. # INPUTS:
  3. # df : data frame
  4. # column_name : string value of column name in df
  5. # input_vec : character vector of values in column_name of df
  6. # OUTPUTS:
  7. # df : filtered dataframe
  8.  
  9. # Main reason for using this is because df$column_name throws
  10. # error as column_name is not a column in df
  11. # We need the column_name input to be used
  12.  
  13. # Expressing the dplyr statement
  14. # column_name %in% input_vec using interp
  15. filter_criteria <- interp(~x %in% y, .values = list(x = as.name(column_name), y = input_vec))
  16.  
  17. # filter_ instead of filter
  18. df %>%
  19. filter_(filter_criteria) -> df
  20.  
  21. return(df)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement