I can define a dataframe running this code:
set.seed(1)
df <- data.frame( ABC_1 = sample(0:1,3,repl = TRUE),
ABC_2 = sample(0:1,3,repl = TRUE),
XYZ_1 = sample(0:1,3,repl = TRUE),
XYZ_2 = sample(0:1,3,repl = TRUE),
CDE_1 = sample(0:1,3,repl = TRUE) )
This is the command to subset data to contain only columns whose names match a condition - having ABC in the name.
df1 <- df[ , grepl( "ABC" , names( df ) ) ]
I want the inverse. I want to subset data to contain only columns whose names match a condition - not having ABC in the name.
Can you help me please?