© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
M. TollefsonR 4 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-7924-3_14

14. The ifelse( ) and switch( ) Functions

Margot Tollefson1  
(1)
Vanward Statistics, PO Box 286, 612 Teneyck Avenue, Stratford, IA, 50249-0286, USA
 

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

The ifelse( ) Function

The ifelse() function chooses what value to return based on whether the first argument ...

Get R 4 Quick Syntax Reference: A Pocket Guide to the Language, API's and Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.