rray_if_else: Conditional selection

Description Usage Arguments Details Examples

View source: R/logical.R

Description

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.

Usage

1
rray_if_else(condition, true, false)

Arguments

condition

A logical vector, matrix, array of rray.

true

A vector, matrix, array, or rray. This is the value in the result when condition is TRUE.

false

A vector, matrix, array, or rray. This is the value in the result when condition is FALSE.

Details

The dimension names of the output are taken as the common names of true and false.

Examples

 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)

DavisVaughan/rray documentation built on Feb. 5, 2020, 10:06 p.m.