library("broadcast")
x.dim <- c(4:2)
x.len <- prod(x.dim)
x.data <- sample(c(NA, 1.1:1000.1), x.len, TRUE)
x <- array(x.data, x.dim)
y <- array(1:50, c(4,1,1))
bc.d(x, y, "+")
## , , 1
##
## [,1] [,2] [,3]
## [1,] 587.1 410.1 145.1
## [2,] 683.1 746.1 778.1
## [3,] 901.1 13.1 733.1
## [4,] 587.1 154.1 438.1
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 570.1 639.1 700.1
## [2,] 103.1 461.1 523.1
## [3,] 539.1 633.1 605.1
## [4,] 592.1 774.1 533.1
bc.d(x, y, "-")
## , , 1
##
## [,1] [,2] [,3]
## [1,] 585.1 408.1 143.1
## [2,] 679.1 742.1 774.1
## [3,] 895.1 7.1 727.1
## [4,] 579.1 146.1 430.1
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 568.1 637.1 698.1
## [2,] 99.1 457.1 519.1
## [3,] 533.1 627.1 599.1
## [4,] 584.1 766.1 525.1
bc.d(x, y, "*")
## , , 1
##
## [,1] [,2] [,3]
## [1,] 586.1 409.1 144.1
## [2,] 1362.2 1488.2 1552.2
## [3,] 2694.3 30.3 2190.3
## [4,] 2332.4 600.4 1736.4
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 569.1 638.1 699.1
## [2,] 202.2 918.2 1042.2
## [3,] 1608.3 1890.3 1806.3
## [4,] 2352.4 3080.4 2116.4
bc.d(x, y, "/")
## , , 1
##
## [,1] [,2] [,3]
## [1,] 586.1000 409.100000 144.1000
## [2,] 340.5500 372.050000 388.0500
## [3,] 299.3667 3.366667 243.3667
## [4,] 145.7750 37.525000 108.5250
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 569.100 638.1000 699.100
## [2,] 50.550 229.5500 260.550
## [3,] 178.700 210.0333 200.700
## [4,] 147.025 192.5250 132.275
bc.d(x, y, "^")
## , , 1
##
## [,1] [,2] [,3]
## [1,] 5.861000e+02 4.091000e+02 1.441000e+02
## [2,] 4.638972e+05 5.536848e+05 6.023312e+05
## [3,] 7.243927e+08 1.030301e+03 3.891769e+08
## [4,] 1.156038e+11 5.076014e+08 3.551069e+10
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 5.691000e+02 6.381000e+02 6.991000e+02
## [2,] 1.022121e+04 2.107728e+05 2.715452e+05
## [3,] 1.540769e+08 2.501661e+08 2.182759e+08
## [4,] 1.196203e+11 3.517131e+11 7.837022e+10
bc.d(x, y, "==")
## , , 1
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
bc.d(x, y, "!=")
## , , 1
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
bc.d(x, y, "<")
## , , 1
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
bc.d(x, y, ">")
## , , 1
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
bc.d(x, y, "<=")
## , , 1
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
bc.d(x, y, ">=")
## , , 1
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUEbc.d
Broadcasted Decimal Numeric Operations
Description
The bc.d() function performs broadcasted decimal numeric operations on 2 numeric or logical arrays.
Usage
bc.d(x, y, op, ...)
## S4 method for signature 'ANY'
bc.d(x, y, op, tol = sqrt(.Machine$double.eps))
Arguments
x, y
|
conformable vectors/arrays of type logical or numeric. |
op
|
a single string, giving the operator. Supported arithmetic operators: +, -, *, /, ^, pmin, pmax. Supported relational operators: ==, !=, <, >, <=, >=, d==, d!=, d<, d>, d<=, d>=. |
…
|
further arguments passed to or from methods. |
tol
|
a single number between 0 and 0.1, giving the machine tolerance to use for the relational operators. Only relevant for the following operators: d==, d!=, d<, d>, d<=, d>= See the %d==%, %d!=%, %d<%, %d>%, %d<=%, %d>=% operators from the ‘tinycodet’ package for details. |
Value
For arithmetic operators:
A numeric array as a result of the broadcasted decimal arithmetic operation.
For relational operators:
A logical array as a result of the broadcasted decimal relational comparison.