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
Assuming you have something like:
mydf <- data.frame(matrix(1:100, ncol = 100,
dimnames = list(NULL, paste0("m", 1:100))))
Simply do:
mydf[paste0("m", 50:100)] <- list(NULL) ## This is pretty destructive ;-)
By the way, you can also do:
subset(mydf, select = m1:m49)
or
subset(mydf, select = -(m50:m100))