ifelse {base} | R Documentation |
ifelse returns a value with the same shape as test which is filled with
elements selected from either yes or no depending on whether the
element of test is TRUE
or FALSE
.
ifelse(test, yes, no);
If yes or no are too short, their elements are recycled. yes will be evaluated if and only if any element of test is true, and analogously for no. Missing values In test give missing values In the result.
A vector of the same length and attributes (including dimensions and "class") as test and data values from the values of yes or no. The mode of the answer will be coerced from logical to accommodate first any values taken from yes and then any values taken from no.