| bc_ifelse | R Documentation |
The bc_ifelse() function
performs a broadcasted form of ifelse().
bc_ifelse(test, yes, no, ...)
## S4 method for signature 'ANY'
bc_ifelse(test, yes, no)
test |
a vector or array,
with the type |
yes, no |
conformable arrays of the same type. |
... |
further arguments passed to or from methods. |
The output, here referred to as out,
will be an array of the same type as yes and no.
If test has the same dimensions as bc_dim(yes, no),
then out will also have the same dimnames as test.
If test is a broadcaster, then out will also be a broadcaster.
After broadcasting yes against no,
given any element index i,
the following will hold for the output:
when test[i] == TRUE, out[i] is yes[i];
when test[i] == FALSE, out[i] is no[i];
when test[i] is NA,
out[i] is NA when yes and no are atomic,
and out[i] is list(NULL) when yes and no are recursive.
x.dim <- c(5, 3, 2)
x.len <- prod(x.dim)
x <- array(sample(1:100), x.dim)
y <- array(sample(1:100), c(5, 1, 1))
cond <- bc.i(x, y, ">")
bc_ifelse(cond, yes = x^2, no = -y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.