[ top | up ]

Conditional Element Selection

Syntax

ifelse(test, yes, no)

Description

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. If yes or no are too short, their elements are recycled.

Examples

x <- ifelse(x > 0, sqrt(x), 0)