'Logic' operations on SparseArray objects
SparseArray-Logic-methods.Rd
SparseArray derivatives support operations from the Logic
group (i.e. &
and |
), with some restrictions.
See ?S4groupGeneric
in the methods package
for more information about the Logic
group generic.
IMPORTANT NOTES:
Only SVT_SparseArray objects are supported at the moment. Support for COO_SparseArray objects might be added in the future.
In base R,
Logic
operations support input oftype()
"logical"
,"integer"
,"double"
, or"complex"
. However, the corresponding methods for SVT_SparseArray objects only support objects oftype()
"logical"
for now.
Value
A SparseArray derivative of type()
"logical"
and
same dimensions as the input object(s).
See also
S4groupGeneric
in the methods package.SparseArray objects.
Ordinary array objects in base R.
Examples
svt1 <- svt2 <- SVT_SparseArray(dim=c(15, 6))
svt1[cbind(1:15, 2)] <- c(TRUE, FALSE, NA)
svt1[cbind(1:15, 5)] <- c(TRUE, NA, NA, FALSE, TRUE)
svt2[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <- c(TRUE, NA)
svt1 & svt2
#> <15 x 6 SparseMatrix> of type "logical" [nzcount=9 (10%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] FALSE TRUE FALSE FALSE NA FALSE
#> [2,] FALSE FALSE FALSE FALSE NA FALSE
#> [3,] FALSE FALSE FALSE FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE FALSE FALSE FALSE
#> [5,] FALSE FALSE FALSE FALSE FALSE FALSE
#> ... . . . . . .
#> [11,] FALSE FALSE FALSE FALSE FALSE FALSE
#> [12,] FALSE NA FALSE FALSE FALSE FALSE
#> [13,] FALSE TRUE FALSE FALSE FALSE FALSE
#> [14,] FALSE FALSE FALSE FALSE FALSE FALSE
#> [15,] FALSE NA FALSE FALSE FALSE FALSE
svt1 | svt2
#> <15 x 6 SparseMatrix> of type "logical" [nzcount=39 (43%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] FALSE TRUE NA FALSE TRUE FALSE
#> [2,] TRUE NA TRUE FALSE TRUE FALSE
#> [3,] FALSE NA NA FALSE NA FALSE
#> [4,] FALSE TRUE FALSE FALSE FALSE FALSE
#> [5,] FALSE FALSE FALSE FALSE TRUE FALSE
#> ... . . . . . .
#> [11,] FALSE TRUE FALSE FALSE TRUE FALSE
#> [12,] TRUE NA FALSE FALSE NA FALSE
#> [13,] NA TRUE FALSE FALSE NA FALSE
#> [14,] TRUE NA FALSE NA FALSE FALSE
#> [15,] NA TRUE FALSE TRUE TRUE NA
## Sanity checks:
m1 <- as.matrix(svt1)
m2 <- as.matrix(svt2)
stopifnot(
identical(as.matrix(svt1 & svt2), m1 & m2),
identical(as.matrix(svt1 | svt2), m1 | m2)
)