A version of
if_else
for the situation where condition
is an rvec.
Arguments
- condition
An object of class rvec_lgl.
- true, false
Vectors (including rvecs) to use for
TRUE
andFALSE
values ofcondition
.- missing
Vectors to use for
NA
values ofcondition
. Optional.- size
Length of output. Optional.
Value
An rvec with the same number of
draws as condition
.
Examples
x <- rvec(list(c(1, 11),
c(2, 5),
c(22, 6)))
x > 10 ## rvec_lgl
#> <rvec_lgl<2>[3]>
#> [1] F,T F,F T,F
## if_else_rvec needed when
## 'condition' is an rvec
if_else_rvec(x > 10, 10, x)
#> <rvec_dbl<2>[3]>
#> [1] 1,10 2,5 10,6
## dplyr::if_else works when
## 'true', 'false', or 'missing'
## (but not 'condition') are rvecs
library(dplyr)
if_else(c(TRUE, FALSE, TRUE), x, 100)
#> <rvec_dbl<2>[3]>
#> [1] 1,11 100,100 22,6