I'm trying to create a variable (df$check6) that has a 1 if ANY of the following are true using the following code:
df$check <- ifelse(df$var1 == 1 & df$var2 == 1, 1,0)
df$check2 <- ifelse(df$var3 == 1 & df$var4 == 1, 1,0)
df$check3 <- ifelse(df$var5 == 1 & df$var6 == 1, 1, 0)
df$check4 <- ifelse(df$var7 >=4 & df$var8 == 1, 1,0)
df$check5 <- ifelse(df$var9 >=4 & df$var10 == 1, 1,0)
df$check6 <- ifelse(df$check== 1 | df$check2 == 1 | df$check3 == 1 | df$check4 == 1, df$check5 == 1, 1,0)
When I run the code, my df$var7 and df$var9 are all changed to 1 when they were originally a "." in my dataset. My >=4 condition does also not appear to be working. My df$check6 = 1 when those 2 variables are numeric values of "2", when the condition is that they should be equal to or greater than 4.
I know there must be a simpler way to do this but I just tried to use the basics. Any suggestions would be appreciated!
EDIT: var 1, 3, 5 were stored as either 1, 0 or "." I created a subset that only included values that were == 1 (excluding 0 and "." cases)
Converted var 1-6,8,10 to logical, as suggested 7,9 were numeric
Answer provided then worked perfectly on my dataset.