case | R Documentation |
Map elements of a vector according to the provided 'cases'. This
function is useful for mapping discrete values to factor labels and
is the vector equivalent to the switch
function.
case(x, ..., default = NA)
x |
Vector to be converted |
... |
Map of alternatives, specified as "name"=value |
default |
Value to be assigned to elements of |
This function is to switch
what ifelse
is to if
,
and is a convenience wrapper for factor
.
A factor variables with each element of x
mapped into the
corresponding level of specified in the mapping.
Gregory R. Warnes greg@warnes.net
factor
, switch
, ifelse
## default = NA
case(c(1,1,4,3), "a"=1, "b"=2, "c"=3)
## default = "foo"
case(c(1,1,4,3), "a"=1, "b"=2, "c"=3, default="foo")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.