All it does is take a vector of T/F, then returns values from two other vectors depending on the case. It's also possible to just return one value for either T or F, as you are doing here (the sum or 0).
Example:
# Vector input, one possible true of false answer
ifelse((1:5 %% 2) == 0, "even", "odd")
#> [1] "odd" "even" "odd" "even" "odd"
# Vector input, pick corresponding index value from true or false vectors
ifelse((1:5 %% 2) == 0, letters[1:5], LETTERS[1:5])
#> [1] "A" "b" "C" "d" "E"
Thank you sm! The solution you give does fix the error. Unfortunately, like you said, your code does not capture the function I provided. It's ok. I'll figure it out.