I'm trying to write a nested ifelse statement which returns either a 1 or 0 based on sti history. The questionnaire scale is NA, None, 1, 2, 3-5, 6-9, 10-19, 20+. If the subject endorses ever having an sti based on four questions then they would get a 1 and if not then a 0.
So far I have written:
sti <- ifelse(CADD_PRS$RBQ22 %in% c("1","2","3-5","6-9","10-19", "20+") | CADD_PRS$RBQ23 %in% c("1","2","3-5","6-9","10-19", "20+") | (CADD_PRS$RBQ24 %in% c("1","2","3-5","6-9","10-19", "20+") | (CADD_PRS$RBQ25 %in% c("1","2","3-5","6-9","10-19", "20+"), 1, 0)
where CADD_PRS is a data frame of the four appended columns.
However, I get this as an error:
Error: unexpected ',' in "sti <- ifelse(CADD_PRS$RBQ22 %in% c("1","2","3-5","6-9","10-19", "20+") | CADD_PRS$RBQ23 %in% c("1","2","3-5","6-9","10-19", "20+") | (CADD_PRS$RBQ24 %in% c("1","2","3-5","6-9","10-19", "20+"
Any idea what I'm doing wrong?