How to drop columns by name pattern in R?

I found a simple answer using dplyr/tidyverse. If your colnames contain “This”, then all variables containing “This” will be dropped.

library(dplyr) 
df_new <- df %>% select(-contains("This"))

Leave a Comment