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, no = -1)
## , , 1
##
## [,1] [,2] [,3]
## [1,] 41 51 32
## [2,] 18 89 64
## [3,] -1 -1 93
## [4,] -1 34 59
## [5,] 49 -1 -1
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 24 70 65
## [2,] -1 25 61
## [3,] -1 -1 -1
## [4,] 37 69 97
## [5,] -1 -1 -1
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
.
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.