The code below shows how I am accomplishing this right now, but I am wondering if there is a way to do this with less code by using col1:col12, or something like that. I tried googling and couldn't figure it out.
MRE:
a = matrix(1:2,12,12)
a= as.data.frame(a)
a = a %>% mutate(col = case_when(V1 == 1 & V2 == 1 & V3 == 1 & V4 == 1 & V5 == 1 & V6 == 1 & V7 == 1 & V8 == 1 & V9 == 1 & V10 == 1 & V11 == 1 & V12 == 1~0)) %>% mutate(col = ifelse(is.na(col),1,col))
There is a lot of code and I know there must be a faster way to do this. I have 12 columns with varying values and I need to check the values in all 12 (using & and |) to create dummy variables indicating whether each row contains specific values. In my actual data set there is a larger range of values in all 12 columns. Any help would be appreciated.