library("broadcast")
# checkNA ====
x <- array(
sample(c(-10:10, NA, NaN)), dim = 4:2
)
y <- array(
sample(c(-10:10, NA, NaN)), dim = c(4,1,1)
)
broadcaster(x) <- broadcaster(y) <- TRUE
mx <- checkNA(x, "raw")
my <- checkNA(y, "raw")
bc.b(mx, my, "&")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 00 00
#>
#> broadcaster
bc.b(mx, my, "xor")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 01 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 01 00 00
#> [4,] 00 00 00
#>
#> broadcaster
bc.b(mx, my, "nand")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 01 00 01
#> [2,] 01 01 01
#> [3,] 01 01 01
#> [4,] 01 01 01
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 01 01 01
#> [2,] 01 01 01
#> [3,] 00 01 01
#> [4,] 01 01 01
#>
#> broadcaster
bc.b(mx, my, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 01 00 01
#> [2,] 01 01 01
#> [3,] 01 01 01
#> [4,] 01 01 01
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 01 01 01
#> [2,] 01 01 01
#> [3,] 00 01 01
#> [4,] 01 01 01
#>
#> broadcaster
bc.b(mx, my, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 01 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 01 00 00
#> [4,] 00 00 00
#>
#> broadcaster
bc_ifelse(bc.b(mx, my, "|"), -1000L, x + y)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 6 -1000 9
#> [2,] -1 -5 -8
#> [3,] 18 -1 6
#> [4,] -17 -4 -9
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 10 4 7
#> [2,] 9 -4 -6
#> [3,] -1000 5 -2
#> [4,] -10 -7 -6
#>
#> broadcaster
# checkNULL ====
x <- array(
sample(list(letters, LETTERS, month.abb, month.name, NULL)), dim = 4:2
)
y <- array(
sample(list(letters, LETTERS, month.abb, month.name, NULL)), dim = c(4,1,1)
)
broadcaster(x) <- broadcaster(y) <- TRUE
mx <- checkNULL(x, "raw")
my <- checkNULL(y, "raw")
bc.b(mx, my, "&")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 00
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 01 00 00
#>
#> broadcaster
bc.b(mx, my, "xor")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 01 00 00
#> [2,] 00 01 00
#> [3,] 00 00 01
#> [4,] 01 01 01
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 01
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 01 01
#>
#> broadcaster
bc.b(mx, my, "nand")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 01 01
#> [2,] 01 00 01
#> [3,] 01 01 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 01 01 00
#> [2,] 01 01 01
#> [3,] 01 01 01
#> [4,] 00 00 00
#>
#> broadcaster
bc.b(mx, my, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 00 01 01
#> [2,] 01 00 01
#> [3,] 01 01 00
#> [4,] 00 00 00
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 01 01 00
#> [2,] 01 01 01
#> [3,] 01 01 01
#> [4,] 01 00 00
#>
#> broadcaster
bc.b(mx, my, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 01 00 00
#> [2,] 00 01 00
#> [3,] 00 00 01
#> [4,] 01 01 01
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 00 00 01
#> [2,] 00 00 00
#> [3,] 00 00 00
#> [4,] 00 01 01
#>
#> broadcaster
bc_ifelse(bc.b(mx, my, "|"), list(~ "Nothing"), bc.list(x, y, paste0))
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] ~"Nothing" character,26 character,26
#> [2,] character,26 ~"Nothing" character,26
#> [3,] character,12 character,12 ~"Nothing"
#> [4,] ~"Nothing" ~"Nothing" ~"Nothing"
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] character,26 character,26 ~"Nothing"
#> [2,] character,26 character,26 character,26
#> [3,] character,26 character,26 character,12
#> [4,] ~"Nothing" ~"Nothing" ~"Nothing"
#>
#> broadcastercheckmissing
Efficiently Check for (Non-)Missing Values
Description
The checkNULL() function efficiently checks for the presence (or absence) of NULL in every element of a list.
The checkNA() function efficiently checks for the presence (or absence) of NA/NaN in every element of an atomic vector.
Usage
checkNA(x, ...)
## Default S3 method:
checkNA(x, op, inv = FALSE, ...)
checkNULL(x, ...)
## Default S3 method:
checkNULL(x, op, inv = FALSE, ...)
Arguments
x
|
an object. For checkNULL(): a recursive vector or array (i.e. type of list). For checkNA(): an atomic vector or array (raw type not supported). |
β¦
|
further arguments passed to or from methods. |
op
|
a single string, giving the operation to use.
|
inv
|
Boolean, indicating if the check should be inverted. If inv = FALSE (default), the operations check for missing elements. If inv = TRUE, the operations check for NOT missing elements. |
Value
Output depends on the specification of argument op:
-
"logical": logical vector with the same length, names, and dimensions as
x. -
"raw": raw vector with the same length, names, and dimensions as
x. -
"any":
TRUEorFALSE. -
"all":
TRUEorFALSE. -
"count" or "sum": 53 bit integer scalar.
-
"which": vector of indices.
-
"first": the first index found, or
0otherwise. -
"last": the last index found, or
0otherwise.