I have this dataframe:
state county city region mmatrix X1 X2 X3 A1 A2 A3 B1 B2 B3 C1 C2 C3 1 1 1
Just as an additional answer, since I stumbled across this, when looking for the data.table solution to this problem.
data.table
library(data.table) dt <- data.table(df) drop.cols <- grep("1$", colnames(dt)) dt[, (drop.cols) := NULL]