Skip to contents

The function vswitch is a vectorized version of base::switch() optimized for performance.

Usage

vswitch(EXPR, ...)

Arguments

EXPR

an expression evaluating to a number or a character string.

...

the list of alternatives. If it is intended that EXPR has a character-string value these will be named, perhaps except for one alternative to be used as a ‘default’ value.

Value

The value of one of the elements of ..., or NA whenever no element is selected. Contrary to base::switch() the result is always visible.

Details

Only the EXPR argument is treated as a vector. In particular, if any of the alternatives (or the default alternative) is a vector, the result will be a list of vectors.