[r] Ifelse statement in R with multiple conditions