| if_else | R Documentation |
if_else() returns a vector filled with elements selected from true,
false, and (optionally) na based on the value of condition. It
is a type- and size-stable version of ifelse().
if_else(condition, true, false, na = NULL)
condition |
A logical vector. |
true, false |
Values to use for |
na |
Values to use for |
A vector with the common type of true, false, and na; and the size of
condition. Where condition is TRUE, the result comes from true,
where FALSE it comes from false.
x <- c(NA, 1:4)
if_else(x > 2, 1, 2)
if_else(x > 2, "small", "big")
if_else(x > 2, factor("small"), factor("big"))
y <- as.Date("2020-01-01")
if_else(x > 2, NA, y + x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.