R: is.na() Methods for 'Matrix' Objects

is.na-methods {Matrix} | R Documentation

## is.na() Methods for 'Matrix' Objects

### Description

Methods for function `is.na()` for all Matrices (objects extending the `Matrix` class):

x = "denseMatrix"

  returns a `"nMatrix"` object of same dimension as `x`, with TRUE's whenever `x` was NA.

x = "sparseMatrix"

  ditto.

### Usage

    ## S4 method for signature 'sparseMatrix'
    is.na(x)

### Arguments

`x` | sparse or dense matrix.

### See Also

`NA`, `is.na`; `nMatrix`, `denseMatrix`, `sparseMatrix`.

### Examples

    M <- Matrix(1:6, nrow=4, ncol=3,
           dimnames = list(c("a", "b", "c", "d"), c("A", "B", "C")))
    stopifnot(all(!is.na(M)))
    M[2:3,2] <- NA
    is.na(M)

    A <- spMatrix(10,20, i = c(1,3:8),
                         j = c(2,9,6:10),
                         x = 7 * (1:7))
    stopifnot(all(!is.na(A)))
    A[2,3] <- A[1,2] <- A[5, 5:9] <- NA
    inA <- is.na(A)
    stopifnot(sum(inA) == 1+1+5)

[Package Matrix version 1.0-6 Index]