allNA: Find Rows or Columns with Only NAs Over Array Margins

View source: R/Data_handling.R

allNAR Documentation

Find Rows or Columns with Only NAs Over Array Margins

Description

allNA returns a logical vector or array or list indicating whether there are only NA values in selected margins and therefore e.g. statistics like max or min do not produce useful results.

Usage

allNA(x, margin)

Arguments

x

An array, including a matrix.

margin

A vector giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. Where x has named dimnames, it can be a character vector selecting dimension names.

See Also

NA for general information about NAs and apply for apply description.

Examples

## Not run: 
xx <- matrix(1:20, nrow = 4)
xx[2, ] <- NA
allNA(xx, 2) # All columns have at least one non-missing value
allNA(xx, 1) # Second row has all values missing
apply(xx, 1, max, na.rm = TRUE)
## returns c(17, -Inf, 19, 20) and a warning message
## Skip the allNA row in apply()
apply(xx[!allNA(xx, 1), ], 1, max, na.rm = TRUE)

## End(Not run)

lsigut/openeddy documentation built on Aug. 5, 2023, 12:25 a.m.