I don't understand what you are trying to do but from your code, you might want to use dplyr::case_when()
function instead of deeply nested ifelse()
conditions.
If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.