i am trying to generate a new variable as follows:
if value for testA is 1 and value for testB is 1 ==> code testAB as 1
if value for testA is 1 and value for testB is missing or 0 ==> code testAB as 1
if value for testA is missing or 0 and value for testB is 1 ==> code testAB as 1
if value for testA is 0 and value for testB is 0 ==> code testAB as 0
if value for testA is missing and value for testB is missing ==> code testAB as NA
the code i came up with shown below does not work. it seems only to generate a 1 if testA and testB are 1, and NA otherwise. what do you recommend? thank you!
df2$testAB<-ifelse((df1$testA == 1) | (df1$testB == 1),1,0),1, 0,NA))