View source: R/replace-na-if.R
replace_na_if | R Documentation |
Unlike tidyr::replace_na()
, it is only defined for vectors.
replace_na_if(x, condition, true)
x |
Vector with missing values to modify. |
condition |
A logical vector |
true |
The replacement values where condition is |
replace_na_if()
is a wrapper on if_else2(is.na(x) & condition, true, x)
A modified version of x that replaces any missing values where condition is TRUE
with true
.
tidyr::replace_na()
and if_else2()
data <- tibble::tibble(
x = c(TRUE, FALSE, NA),
y = c("x is false", NA, "x is false")
)
dplyr::mutate(data,
x1 = tidyr::replace_na(x, FALSE),
x3 = if_else2(is.na(x) & y == "x is false", FALSE, x),
x4 = replace_na_if(x, y == "x is false", FALSE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.