NaArray-Logic-methods: 'Logic' operations on NaArray objects

NaArray-Logic-methodsR Documentation

'Logic' operations on NaArray objects

Description

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.

Details

Three forms of 'Logic' operations involving NaArray objects are supported:

  1. Between an NaArray object naa and a single logical value y:

        naa op y
        y op naa
  2. Between two NaArray objects naa1 and naa2 of same dimensions (a.k.a. conformable arrays):

        naa1 op naa2
  3. 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.

Value

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.

See Also

  • S4groupGeneric in the methods package.

  • NaArray objects.

  • SVT_SparseArray objects.

  • Ordinary array objects in base R.

Examples

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)
)

Bioconductor/SparseArray documentation built on Oct. 30, 2024, 12:14 p.m.