Switch {hutils} | R Documentation |
Vectorized switch
Description
Present since hutils 1.2.0
. Vectorized version of switch
. Used to avoid or make clearer the result of
if_else(Expr == , ..1, if_else(Expr == , ..2, ...))
Usage
Switch(Expr, ..., DEFAULT, IF_NA = NULL, MUST_MATCH = FALSE)
Arguments
Expr |
A character vector. |
... |
As in |
DEFAULT |
A mandatory default value should any name of |
IF_NA |
Optional value to replace missing ( |
MUST_MATCH |
(logical, default: |
Value
For every element of ...
whose name matches an element of Expr
,
that element's value.
Examples
Switch(c("a", "b", "c", "a"),
"a" = 1,
"b" = 2,
"c" = 3,
"4" = 4,
DEFAULT = 0)
[Package hutils version 1.8.1 Index]