Description Usage Arguments Value Examples
The normal behavior for the ifelse
function is to return the resulting vector
with a class type coerced to be the same as the yes
argument. However, when
a Date type vector is passed as an argument, Dates lose their class when the
condition is evaluated. The resulting vector is of type numeric.
This function safe_ifelse
modifies the normal behavior for Date vectors.
Users can specify whether to coerce to any class or the default will be used
which is class(no)
.
1 | safe_ifelse(cond, yes, no, class_to_use = class(no))
|
cond |
the test to determine if yes/no |
yes |
the value or operation to return if |
no |
the value or operation to return if |
the resulting vector coerced to class type class_to_use
1 2 | d = as.Date(c("2015-01-01","2015-08-08"))
safe_ifelse(d=="2015-01-01",d-10,d)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.