Conditional Execution

There are four conditionals:
if (expression1) expression2
if (expression1) expression2 else expression3
ifelse (condition, a, b)
switch (expression1, alternative1, alternative2, ... )

Often expression2 and/or expression3 are grouped expressions.

The vectorized version is:

ifelse(condition, a, b)

returns a[i] if condition[i] is TRUE and b[i] otherwise.

Notice that if condition[i] evaluates to a nonzero numeric it is the coerced to TRUE.