vswitch: A vectorized version of switch

Description Usage Arguments Author(s) Examples

Description

A vectorized version of switch.

Usage

1
vswitch(EXPR, ...)

Arguments

EXPR

As in switch, an expression which evaluated to a number or character string. However, in vswitch, there can be more than one.

...

Passed to switch

Author(s)

Brendan Rocks rocks.brendan@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# The usual version of 'switch' works perfectly with one value
x <- "a"
switch(x, a = 1, b = 2, c = 3)

# But not with more than one
x <- letters[1:3]
## Not run: switch(x, a = 1, b = 2, c = 3)

# vswitch works well where you'd like to 'switch' a vector
x <- letters[1:3]
vswitch(x, a = 1, b = 2, c = 3)

brendan-R/brocks documentation built on May 13, 2019, 5:07 a.m.