rvar_ifelse: Random variable ifelse

View source: R/rvar-.R

rvar_ifelseR Documentation

Random variable ifelse

Description

A version of ifelse() that returns an rvar.

Usage

rvar_ifelse(test, yes, no)

Arguments

test

(logical rvar, or castable to one) logical test determining whether the value in yes or no is assigned in the corresponding position of the result.

yes

(rvar, or castable to one) corresponding values assigned for entries in test that are TRUE.

no

(rvar, or castable to one) corresponding values assigned for entries in test that are FALSE.

Value

An rvar with the common type of yes and no (as determined by vctrs::vec_cast_common()) and a shape determined by broadcasting test, yes, and no to a common shape (see the section on broadcasting rules in vignette("rvar")). For every element of draws_of(test), the corresponding element of draws_of(yes) or draws_of(no) is placed into the result, depending on whether the element of test is TRUE or FALSE.

Examples

x <- rvar(1:4)
y <- rvar(5:8)

i <- rvar(c(TRUE,FALSE,TRUE,FALSE))
z <- rvar_ifelse(i, x, y)
z
draws_of(z)

posterior documentation built on Nov. 2, 2023, 5:56 p.m.