How to use select on multiple fields using dplyr
I have a character vector of the field names that I want to select using dplyr. I am using select _ () underscore string.
select(mtcars, mpg) # works OK
select(mtcars, mpg, disp, am) # works OK for multiple fields
now use the underscore version
fie <- c("mpg")
select_(mtcars, fie) # works OK for one
fie <- c("mpg", "disp", "am")
select_(mtcars, fie) # problem: only returns one column
select_(mtcars, ~fie) # problem: doesn't work
I am confused as to how to get this to work. Any suggestions? thank
+3
source to share