ifelse | R Documentation |
base::ifelse
The ifelse
function does weird
things when you pass it factors.
This version doesn't.
ifelse(test, yes, no)
test |
a vector of logicals |
yes |
values to return if test is TRUE |
no |
values to return if test if FALSE |
For each position, ifelse
returns
the value of yes
or no
depending on the value of test
.
ifelse(
c(TRUE, FALSE),
c('Yes', 'Yeah!'),
c('No', 'Nope'))
# base ifelse does weird stuff with factors
yesf <- factor(c('Yes', 'Yeah!'))
nof <- factor(c('No', 'Nope'))
base::ifelse(c(TRUE, FALSE), yesf, nof)
alrtools::ifelse(c(TRUE, FALSE), yesf, nof)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.