# is.na-methods: is.na(), is.finite() Methods for 'Matrix' Objects In Matrix: Sparse and Dense Matrix Classes and Methods

 is.na-methods R Documentation

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

### Description

Methods for generic functions `is.na()`, `is.nan()`, `is.finite()`, `is.infinite()`, and `anyNA()`, for objects inheriting from virtual class `Matrix` or `sparseVector`.

### Usage

```## S4 method for signature 'dsparseMatrix'
is.na(x)
## S4 method for signature 'dsparseMatrix'
is.nan(x)
## S4 method for signature 'dsparseMatrix'
is.finite(x)
## S4 method for signature 'dsparseMatrix'
is.infinite(x)
## S4 method for signature 'dsparseMatrix'
anyNA(x)
## ...
## and for other classes
```

### Arguments

 `x` an R object, here a sparse or dense matrix or vector.

### Value

For `is.*()`, an `nMatrix` or `nsparseVector` matching the dimensions of `x` and specifying the positions in `x` of (some subset of) `NA`, `NaN`, `Inf`, and `-Inf`. For `anyNA`(), `TRUE` if `x` contains `NA` or `NaN` and `FALSE` otherwise.

`NA`, `NaN`, `Inf`

### Examples

```(M <- Matrix(1:6, nrow = 4, ncol = 3,
dimnames = list(letters[1:4], LETTERS[1:3])))
stopifnot(!anyNA(M), !any(is.na(M)))

M[2:3, 2] <- NA
(inM <- is.na(M))
stopifnot(anyNA(M), sum(inM) == 2)

(A <- spMatrix(nrow = 10, ncol = 20,
i = c(1, 3:8), j = c(2, 9, 6:10), x = 7 * (1:7)))
stopifnot(!anyNA(A), !any(is.na(A)))

A[2, 3] <- A[1, 2] <- A[5, 5:9] <- NA
(inA <- is.na(A))
stopifnot(anyNA(A), sum(inA) == 1 + 1 + 5)
```

Matrix documentation built on Nov. 11, 2022, 9:06 a.m.