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,] 408.1 751.1 343.1
#> [2,] 662.1 262.1 887.1
#> [3,] 723.1 478.1 214.1
#> [4,] 467.1 679.1 401.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 689.1 279.1 833.1
#> [2,] 81.1 387.1 250.1
#> [3,] 41.1 519.1 792.1
#> [4,] 769.1 629.1 58.1
bc.d(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 406.1 749.1 341.1
#> [2,] 658.1 258.1 883.1
#> [3,] 717.1 472.1 208.1
#> [4,] 459.1 671.1 393.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 687.1 277.1 831.1
#> [2,] 77.1 383.1 246.1
#> [3,] 35.1 513.1 786.1
#> [4,] 761.1 621.1 50.1
bc.d(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 407.1 750.1 342.1
#> [2,] 1320.2 520.2 1770.2
#> [3,] 2160.3 1425.3 633.3
#> [4,] 1852.4 2700.4 1588.4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 688.1 278.1 832.1
#> [2,] 158.2 770.2 496.2
#> [3,] 114.3 1548.3 2367.3
#> [4,] 3060.4 2500.4 216.4
bc.d(x, y, "/")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 407.1000 750.1000 342.10000
#> [2,] 330.0500 130.0500 442.55000
#> [3,] 240.0333 158.3667 70.36667
#> [4,] 115.7750 168.7750 99.27500
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 688.100 278.1000 832.1000
#> [2,] 39.550 192.5500 124.0500
#> [3,] 12.700 172.0333 263.0333
#> [4,] 191.275 156.2750 13.5250
bc.d(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 4.071000e+02 7.501000e+02 3.421000e+02
#> [2,] 4.357320e+05 6.765201e+04 7.834020e+05
#> [3,] 3.734035e+08 1.072396e+08 9.407294e+06
#> [4,] 4.599378e+10 2.077172e+11 2.486563e+10
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 6.881000e+02 2.781000e+02 832.10
#> [2,] 6.256810e+03 1.483020e+05 61553.61
#> [3,] 5.530634e+04 1.374680e+08 491355848.97
#> [4,] 3.426674e+11 1.526856e+11 8566216.78
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() 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.