You can use one_of
to find the column positions and then use -
to drop it, select(-one_of(name))
, if you check ?select
, the usage is documented in the Drop variable section in the Examples:
name <- "drop"
a %>% select(-one_of(name))
# A tibble: 2 × 1
# keep
# <chr>
#1 hello
#2 world
Or with select_
, you need to paste -
with the column names to drop them and pass the pasted column names to the .dots
parameter if there are more than one column to be dropped:
name <- "drop"
a %>% select_(.dots = paste("-", name))
# A tibble: 2 × 1
# keep
# <chr>
#1 hello
#2 world
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…