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,] 685.1 216.1 424.1
#> [2,] 303.1 588.1 576.1
#> [3,] 752.1 232.1 407.1
#> [4,] 546.1 NA 579.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 920.1 911.1 845.1
#> [2,] 394.1 238.1 643.1
#> [3,] 757.1 285.1 NA
#> [4,] 868.1 708.1 969.1
bc.d(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 683.1 214.1 422.1
#> [2,] 299.1 584.1 572.1
#> [3,] 746.1 226.1 401.1
#> [4,] 538.1 NA 571.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 918.1 909.1 843.1
#> [2,] 390.1 234.1 639.1
#> [3,] 751.1 279.1 NA
#> [4,] 860.1 700.1 961.1
bc.d(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 684.1 215.1 423.1
#> [2,] 602.2 1172.2 1148.2
#> [3,] 2247.3 687.3 1212.3
#> [4,] 2168.4 NA 2300.4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 919.1 910.1 844.1
#> [2,] 784.2 472.2 1282.2
#> [3,] 2262.3 846.3 NA
#> [4,] 3456.4 2816.4 3860.4
bc.d(x, y, "/")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 684.100 215.10000 423.100
#> [2,] 150.550 293.05000 287.050
#> [3,] 249.700 76.36667 134.700
#> [4,] 135.525 NA 143.775
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 919.1000 910.10000 844.100
#> [2,] 196.0500 118.05000 320.550
#> [3,] 251.3667 94.03333 NA
#> [4,] 216.0250 176.02500 241.275
bc.d(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 6.841000e+02 215.1 4.231000e+02
#> [2,] 9.066121e+04 343513.2 3.295908e+05
#> [3,] 4.203581e+08 12024728.2 6.598824e+07
#> [4,] 8.636099e+10 NA 1.093890e+11
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 9.191000e+02 9.101000e+02 8.441000e+02
#> [2,] 1.537424e+05 5.574321e+04 4.110092e+05
#> [3,] 4.288316e+08 2.244963e+07 NA
#> [4,] 5.575143e+11 2.457748e+11 8.675395e+11
bc.d(x, y, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE NA FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE NA
#> [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 NA TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE NA
#> [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 NA FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE NA
#> [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 NA TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE NA
#> [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 NA FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE NA
#> [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 NA TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE NA
#> [4,] TRUE TRUE TRUEbc.d
Broadcasted Decimal Numeric Operations
Description
The bc.d() method 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.