I have a set of categorical columns in my dataset that I'll be turning into binary variables (1/0).
There are many of these, and currently, I've called the column names and values, transferred into a word document and then used the column values directly in the code:
binarydata<- rawdata3
my_cols = c(8:38, 48:52, 59:69, 96:118, 120:132, 145:148, 154:170, 223:330)
binarydata[my_cols] <- as.integer(!is.na(binarydata[my_cols]))
Is there a way to do it using the variable names, instead of the values?
Any help appreciated,