© Margot Tollefson 2019
Margot TollefsonR Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-4405-0_14

14. The Functions ifelse() and switch()

Margot Tollefson1 
(1)
Stratford, IA, USA
 

The two functions ifelse() and switch() execute flow control within a function or script. 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 ...

Get R Quick Syntax Reference: A Pocket Guide to the Language, APIs and Library now with O’Reilly online learning.

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