bc.raw

Broadcasted Operations that Take Raw Arrays and Return Raw Arrays

Description

The bc.raw() function performs broadcasted operations on arrays of type raw, and the return type is always raw.

For bit-wise operations, use bc.bit.
For relational operations with logical (TRUE/FALSE/NA) results, use bc.rel.

Usage

bc.raw(x, y, op, ...)

## S4 method for signature 'ANY'
bc.raw(x, y, op)

Arguments

x, y conformable raw vectors or arrays.
op a single string, giving the operator.
Supported operators: ==, !=, <, >, <=, >=, pmin, pmax, diff.
The relational operators work the same as in bc.rel, but with the following difference:
a TRUE result is replaced with 01, and a FALSE result is replaced with 00.
The "diff" operator performs the byte equivalent of abs(x - y).
further arguments passed to or from methods.

Value

bc.raw() always returns an array of type raw.
For the relational operators, 01 codes for TRUE results, and 00 codes for FALSE results.

See Also

broadcast_operators

Examples

library("broadcast")


x <- array(
  sample(as.raw(1:100)), c(5, 3, 2)
)
y <- array(
  sample(as.raw(1:100)), c(5, 1, 1)
)

cond <- bc.raw(x, y, "!=")
print(cond)
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]   01   01   01
## [2,]   01   01   01
## [3,]   01   01   01
## [4,]   01   01   01
## [5,]   01   01   01
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   01   01   01
## [2,]   01   01   01
## [3,]   01   01   01
## [4,]   01   01   01
## [5,]   01   01   01

bc_ifelse(cond, yes = x, no = y)
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]   1a   12   53
## [2,]   33   49   11
## [3,]   42   48   25
## [4,]   08   36   4a
## [5,]   05   5e   57
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   63   61   4d
## [2,]   59   60   4b
## [3,]   5a   23   39
## [4,]   3d   34   54
## [5,]   58   16   19