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,] 71.1 182.1 397.1
#> [2,] 891.1 461.1 687.1
#> [3,] NA 295.1 255.1
#> [4,] 262.1 614.1 508.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 8.1 920.1 910.1
#> [2,] 758.1 599.1 320.1
#> [3,] 105.1 403.1 362.1
#> [4,] 42.1 992.1 480.1
bc.d(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 69.1 180.1 395.1
#> [2,] 887.1 457.1 683.1
#> [3,] NA 289.1 249.1
#> [4,] 254.1 606.1 500.1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 6.1 918.1 908.1
#> [2,] 754.1 595.1 316.1
#> [3,] 99.1 397.1 356.1
#> [4,] 34.1 984.1 472.1
bc.d(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 70.1 181.1 396.1
#> [2,] 1778.2 918.2 1370.2
#> [3,] NA 876.3 756.3
#> [4,] 1032.4 2440.4 2016.4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7.1 919.1 909.1
#> [2,] 1512.2 1194.2 636.2
#> [3,] 306.3 1200.3 1077.3
#> [4,] 152.4 3952.4 1904.4
bc.d(x, y, "/")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 70.100 181.10000 396.10000
#> [2,] 444.550 229.55000 342.55000
#> [3,] NA 97.36667 84.03333
#> [4,] 64.525 152.52500 126.02500
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7.10000 919.1000 909.100
#> [2,] 378.05000 298.5500 159.050
#> [3,] 34.03333 133.3667 119.700
#> [4,] 9.52500 247.0250 119.025
bc.d(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 70.1 1.811000e+02 3.961000e+02
#> [2,] 790498.8 2.107728e+05 4.693620e+05
#> [3,] NA 2.492268e+07 1.602207e+07
#> [4,] 4437639495.7 1.385492e+11 6.457535e+10
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7.1 9.191000e+02 9.091000e+02
#> [2,] 571687.2 3.565284e+05 1.011876e+05
#> [3,] 1064332.3 6.404801e+07 4.630695e+07
#> [4,] 2107171.6 9.532429e+11 5.137984e+10
bc.d(x, y, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] NA 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,] NA 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,] NA 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,] NA 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,] NA 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,] NA 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.