narm: Return an object with missing values removed.

View source: R/NCmisc.R

narmR Documentation

Return an object with missing values removed.

Description

Convenience function, removes NAs from most standard objects. Uses function na.exclude for matrices and dataframes. Main difference to na.exlude is that it simply performs the transformation, without adding attributes For unknown types, leaves unchanged with a warning.

Usage

narm(X)

Arguments

X

The object to remove NAs, any vector, matrix or data.frame

Value

Vector minus NA's, or the matrix/data.frame minus NA rows. If it's a character vector then values of "NA" will also be excluded in addition to values = NA, so be careful if "NA" is a valid value of your character vector. Note that "NA" values occur when 'paste(...,NA,...)' is applied to a vector of any type, whereas 'as.character(...,NA,...)' avoids this.

Author(s)

Nicholas Cooper njcooper@gmx.co.uk

Examples

narm(c(1,2,4,NA,5))
DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA))
DF; narm(DF)
# if a list, will only completely remove NA from the lowest levels
# empty places will be left at top levels
print(narm(list(1,2,3,NA,list(1,2,3,NA))))

NCmisc documentation built on Oct. 17, 2022, 5:09 p.m.