vmap: Vectorized map from element to case by index or string value

Description Usage Arguments See Also Examples

View source: R/transform.R

Description

This function is a vectorized version of switch, that is, for each element of input vector, switch is evaluated and the results are combined.

Usage

1
vmap(EXPR, ..., SIMPLIFY = TRUE)

Arguments

EXPR

an expression evaluated to be character or numeric vector/list.

...

The list of alternatives for each switch.

SIMPLIFY

TRUE to simplify the resulted list to vector, matrix or array if possible.

See Also

switch

Examples

1
2
3
4
5
x <- c("normal","normal","error","unknown","unknown")
vmap(x, normal = 0, error = -1, unknown = -2)

x <- c(1,1,2,1,2,2,1,1,2)
vmap(x, "type-A", "type-B")

Example output

[1]  0  0 -1 -2 -2
[1] "type-A" "type-A" "type-B" "type-A" "type-B" "type-B" "type-A" "type-A"
[9] "type-B"

formattable documentation built on Jan. 13, 2021, 7:17 a.m.