I have written the following function in R with two sequential if conditions:
f <- function(a) {
if (a > 10) {
c <- 'a is greater than 10'
c
}
if (a < 10) {
c <- 'a is less than 10'
c
}
}
Calling f(1)
returns 'a is less than 10', however, calling f(11)
returns nothing.
I am confused as to why this happens? The two sequential if statements should in theory have the same effect as an if-else statement, however, if the second condition is triggered instead of the first, no output is returned. I have tried multiple variations of this function, and the same effect is still observed. Any help would be appreciated!