In the function named foo, I assumed that because of working with the if-else when I input a vector for the input values, I get a vector output.
The following function should return > [1] 1 6 in the output, but I am only getting > [1] 1 as the output...
foo <- function(mpre = NA, mpos = NA, mdif = NA){
ifelse(!is.na(mdif), mdif, ifelse(!is.na(mpre) & !is.na(mpre) & is.na(mdif), mpos - mpre, NA))
}
## EXAMPLE:
foo(c(1,3), c(2,9))