pathos
March 22, 2022, 10:40am
1
columns_to_remove = c('b', 'c', 'd')
df |> select.(-all_of(columns_to_remove))
In general, the above code works. However, if column c
does not exist in df
in the first place, it will not work.
How can I remove the columns in the list, similar to %in%
?
vkatti
March 22, 2022, 11:14am
2
Try the following:
columns_to_remove = c('b', 'c', 'd')
df |> select(all_of(!names(df) %in% columns_to_remove))
1 Like
try changing all_of to any_of
1 Like
system
Closed
April 12, 2022, 11:42am
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.