I would like to remove a vector of columns using dplyr >= 0.7
library(dplyr)
data(mtcars)
rem_cols <- c("wt", "qsec", "vs", "am", "gear", "carb")
head(select(mtcars, !!paste0("-", rem_cols)))
Error: Strings must match column names. Unknown columns: -wt, -qsec, -vs, -am, -gear, -carb
dplyr < 0.7 worked as follows:
head(select_(mtcars, .dots = paste0("-", rem_cols)))
# mpg cyl disp hp drat
# Mazda RX4 21.0 6 160 110 3.90
# Mazda RX4 Wag 21.0 6 160 110 3.90
# Datsun 710 22.8 4 108 93 3.85
# Hornet 4 Drive 21.4 6 258 110 3.08
# Hornet Sportabout 18.7 8 360 175 3.15
# Valiant 18.1 6 225 105 2.76
I've tried about all combinations of rlang:syms(), !!, !!!, quo and enquo that I can think of... help!?
We can use one_of
mtcars %>%
select(-one_of(rem_cols))
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