ifelse(test, yes, no)
ifelsereturns a value with the same shape as
testwhich is filled with elements selected from either
nodepending on whether the element of
noare too short, their elements are recycled.
x <- c(6:-4) sqrt(x)#- gives warning sqrt(ifelse(x >= 0, x, NA))# no warning ## Note: the following also gives the warning ! ifelse(x >= 0, sqrt(x), NA)