ez.nan2na: Replaces non-finite values (Inf, -Inf, NaN, NA) with 'NA's in...

View source: R/basic.R

ez.nan2naR Documentation

Replaces non-finite values (Inf, -Inf, NaN, NA) with NAs in array-like objects.

Description

Replaces non-finite values (Inf, -Inf, NaN, NA) with NAs in array-like objects.

Usage

ez.nan2na(x)

Arguments

x

An array-like object, or vector

Value

Returns x with non-finite values (Inf, -Inf, NaN, NA) replaced with NAs.

Note

is.na() returns TRUE for both NA and NaN, however is.nan() return TRUE for NaN (0/0) and FALSE for NA.
mean(c(NA,NA),na.rm=T) —> NaN, mean(c(NA,NA),na.rm=F) —> NA sum(c(NA,NA),na.rm=T) —> 0, sum(c(NA,NA),na.rm=F) —> NA

See Also

is.finite, NA

Examples

ez.nan2na(Inf)
ez.nan2na(rep(c(0, -Inf, Inf, NA, NaN), 3))
ez.nan2na(matrix(c(0, Inf, -Inf, 0), 2, 2))
ez.nan2na(array(c(0, -Inf, Inf, 1, NaN), dim = c(2, 3, 4)))
ez.nan2na(ts(rep(c(0, -Inf, Inf), 2), frequency = 5))
ez.nan2na(factor(c('ab','de'))), ez.nan2na(c('ab','de'))  # returns the original

jerryzhujian9/zmisc documentation built on March 9, 2024, 12:49 a.m.