The Functions ifelse() and switch()

The two functions ifelse() and switch() execute flow control within a function. The function ifelse() evaluates a logical expression and chooses one of two values based on the result. The function switch() takes a value as an argument and returns another value based on the value of the first argument.

The Function ifelse()

The ifelse() function takes three arguments. The first is a logical object or any object that can be coerced to logical, such as objects of the atomic modes or objects of mode list where there is only one level of depth to the list and where each element takes on only one value. ...

Get R Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.