I have a dataset where caseness for a condition is stored across multiple variables, and needs to be collapsed into a single variable by assigning from each one sequentially. The below R code explains what I'm aiming for.
dataset$caseness <- NULL
dataset$caseness[dataset$a_case=="Y"] <- "Yes"
dataset$caseness[dataset$a_case=="N"] <- "No"
dataset$caseness[dataset$b_case=="Y" & is.na(dataset$caseness)] <- "Yes"
dataset$caseness[dataset$b_case=="N" & is.na(dataset$caseness)] <- "No"
dataset$caseness[dataset$c_case=="Y" & is.na(dataset$caseness)] <- "Yes"
dataset$caseness[dataset$c_case=="N" & is.na(dataset$caseness)] <- "No"
#etc.
Some example results of this would be:
a_case b_case c_case caseness
Y NA NA Yes
NA N NA No
N N Y No
NA NA NA NA
This code behaves exactly how I want it to (including the way it handles contradictions), but is long and clumsy, and extends over many lines because I have so many variables denoting caseness. Is there a more efficient way of doing this, for example by looping or similar?