library("broadcast")
<- c(5, 3, 2)
x.dim <- prod(x.dim)
x.len
<- array(sample(1:100), x.dim)
x <- array(sample(1:100), c(5, 1, 1))
y
<- bc.i(x, y, ">")
cond
bc_ifelse(cond, yes = x^2, no = -y)
## , , 1
##
## [,1] [,2] [,3]
## [1,] 4225 8464 -54
## [2,] 3600 -37 1936
## [3,] -74 -74 -74
## [4,] 5929 7569 841
## [5,] -84 8281 -84
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] -54 -54 -54
## [2,] 3721 -37 5776
## [3,] -74 -74 -74
## [4,] 7056 1089 1681
## [5,] -84 8649 9604
bc_ifelse
Broadcasted Ifelse
Description
The bc_ifelse()
function performs a broadcasted form of ifelse()
.
Usage
bc_ifelse(test, yes, no, ...)
## S4 method for signature 'ANY'
bc_ifelse(test, yes, no)
Arguments
test
|
a vector or array, with the type logical , integer , or raw , and a length equal to prod(bc_dim(yes, no)) . If yes / no are of type raw , test is not allowed to contain any NA s.
|
yes , no
|
conformable arrays of the same type. All atomic types are supported. Recursive arrays of type list are also supported. |
…
|
further arguments passed to or from methods. |
Value
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]
isyes[i]
; -
when
test[i] == FALSE
,out[i]
isno[i]
; -
when
test[i]
isNA
,out[i]
isNA
whenyes
andno
are atomic, andout[i]
islist(NULL)
whenyes
andno
are recursive.