| pick | R Documentation |
Return the value associated with test from the supplied vectors.
pick(test, ..., .pass = test, na = NA)
test |
a logical, numeric, or character vector that indicates which value
to select from the data supplied in |
... |
the values to be selected. |
.pass |
the value to return for any element of |
na |
the value to return for any element of |
If test is logical, then if test is TRUE, return the first
argument in ..., otherwise return the second argument.
If test
is numeric, then return that value in the list defined by ...
If test is character, then return that value in the list defined by
..., which must be named in the call.
If test is
NA, then return the value specified by na.
A vector of the same length as test and data values from the
values list defined by ... The mode of the result will be coerced
from the values list defined by ...
This function is designed to replace nested ifelse expressions.
See Examples. It is different from switch in that the value
selected from the possible alternatives is selected by the values in
test rather than by a single value.
ifelse, switch
## Create the test vector
testpick <- c(1,2,3,1)
## Nested ifelse
ifelse(testpick == 1, 1,
ifelse(testpick == 2, 3,
ifelse(testpick == 3, 5, NA)))
## Results by pick:
pick(testpick, 1, 3, 5)
## Create a test vector of character data
testpick <- c("a","b","c","a")
pick(testpick, a=1, b=3, c=5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.