I have a dataframe df with column names from m1 to m100
I want to delete columns in the range m50 to m100. Is there a faster way to do it than hardcoding it
We can assign the columns to NULL in data.table
data.table
library(data.table) setDT(df_cohort)[, paste0('M', 50:100) := NULL]
If we need to subset,
setDT(df_cohort)[, setdiff(names(df_cohort), paste0('m', 50:100)), with=FALSE]