recode_if | R Documentation |
if_else
will replace original data with NA when
conditions has NAs. Handling only a simple case so it is 20 times faster than
case_when
(see Examples).
recode_if(cond, yes, no)
cond |
condition |
yes |
value when condition is true |
no |
value when condition is false **or NA** |
x <- c(rnorm(100), NA_real_)
y <- c(rnorm(100), NA_real_)
bench::mark(
dplyr::case_when(x < 0 ~ 10, T ~ x),
recode_if(x < 0, 10, x),
relative = T
)
bench::mark(
dplyr::case_when(x < 0 ~ y, T ~ x),
recode_if(x < 0, y, x),
relative = T
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.