NaArray-Logic-methods | R Documentation |
EXPERIMENTAL!!!
NaArray objects support operations from the Logic
group
(i.e. &
and |
), as well as logical negation (!
).
See ?S4groupGeneric
in the methods package
for more information about the Logic
group generic.
Note that in base R, Logic
operations support input of type()
"logical"
, "integer"
, "double"
, or "complex"
.
However, the corresponding methods for NaArray objects only
support objects of type()
"logical"
for now.
Three forms of 'Logic' operations involving NaArray objects are supported:
Between an NaArray object naa
and a single
logical value y
:
naa op y y op naa
Between two NaArray objects naa1
and naa2
of same dimensions (a.k.a. conformable arrays):
naa1 op naa2
Between an NaArray object naa
and an
SVT_SparseArray object svt
of same dimensions
(a.k.a. conformable arrays):
naa op svt svt op naa
Note that, in this case, |
returns an NaArray
object but &
returns an SVT_SparseArray object.
An NaArray object of type()
"logical"
and same
dimensions as the input object(s), except when &
is used
between an NaArray object and an SVT_SparseArray object
in which case an SVT_SparseArray object is returned.
S4groupGeneric
in the methods package.
NaArray objects.
SVT_SparseArray objects.
Ordinary array objects in base R.
nam1 <- NaArray(dim=c(15, 6))
nam1[cbind(1:15, 2)] <- c(TRUE, FALSE, NA)
nam1[cbind(1:15, 5)] <- c(TRUE, NA, NA, FALSE, TRUE)
nam1
!nam1
nam1 & NA # replaces all TRUE's with NA's
nam1 | NA # replaces all FALSE's with NA's
nam2 <- NaArray(dim=dim(nam1))
nam2[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <- c(TRUE, NA)
nam2
nam1 & nam2
nam1 | nam2
## Sanity checks:
m1 <- as.matrix(nam1)
m2 <- as.matrix(nam2)
stopifnot(
identical(as.matrix(!nam1), !m1),
identical(as.matrix(nam1 & NA), m1 & NA),
identical(as.matrix(nam1 | NA), m1 | NA),
identical(as.matrix(nam1 & nam2), m1 & m2),
identical(as.matrix(nam1 | nam2), m1 | m2)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.