Description Usage Arguments Details Examples
rray_if_else()
is like ifelse()
, but works with matrices and arrays,
and fully supports broadcasting between the three inputs. Before the
operation is applied, condition
is cast to a logical, and true
and
false
are cast to their common type.
1 | rray_if_else(condition, true, false)
|
condition |
A logical vector, matrix, array of rray. |
true |
A vector, matrix, array, or rray. This is the value in the result
when |
false |
A vector, matrix, array, or rray. This is the value in the
result when |
The dimension names of the output are taken as the common names of true
and false
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | cond <- c(TRUE, FALSE)
true <- array(
1:2,
dimnames = list(c("r1", "r2"))
)
false <- rray(
c(3, 4, 5, 6),
dim = c(2, 2),
dim_names = list(c("rr1", "rr2"), c("c1", "c2"))
)
# - All inputs are broadcast to a common
# shape of (2, 2).
# - The first row of the output comes from
# `true`, the second row comes from `false`.
# - The names come from both `true` and `false`.
rray_if_else(cond, true, false)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.