I have a character vector of field names that I want to select using dplyr. I'm using the underscore version of select_().
select(mtcars, mpg) # works OK
select(mtcars, mpg, disp, am) # works OK for multiple fields
now let's 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'm confused as to how to get this to work. Any suggestions? Thanks
If you use select:
select(mtcars, one_of(fie))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With