na.action
Handle Missing Values in Objects

Description

Filters out missing values (na.exclude, and na.omit causes an error if missing values are encountered (na.fail), or returns the object unchanged (na.pass).

Usage

na.action(object, ...)
## Default S3 method:
na.action(object, ...) 
na.fail(object, ...)
## Default S3 method:
na.fail(object, ...)
na.omit(object, ...)
## S3 method for class 'data.frame':
na.omit(object, ...) 
## Default S3 method:
na.omit(object, ...) 
## S3 method for class 'ts':
na.omit(object, ...) 
na.exclude(object, ...)
## S3 method for class 'data.frame':
na.exclude(object, ...)
## Default S3 method:
na.exclude(object, ...)
na.pass(object, ...)

Arguments

object a data frame, vector, matrix, or time series (of class ts).
... additional arguments that special methods could require.

Details

These functions may be given to model fitting functions such as lm via their na.action argument.
Historically, na.omit was the recommended (and only) method for omitting rows with missing values through the na.action argument. Because of the extra functionality provided by the na.exclude function it is now the recommended na.action.
Value
For na.omit and na.exclude, an object like the input object consisting of the rows (elements) of object for which none of the columns had any missing values. For ts time series object na.omit requires that any missing values be at the ends of the series. na.omit and na.exclude also attach an attribute called "na.action" saying which rows were dropped.
na.pass returns its input, unchanged.
na.fail calls stop (and, hence, returns nothing) if its input contains any NA values, but otherwise returns its input, unchanged.
na.action extracts the "na.action" attribute that one of the other functions may have attached. It looks for either a the attribute or list component by that name.
Side Effects
na.fail causes an error if missing values are present.
References
Chambers, J. M. and Hastie, T .J. (Eds.) 1992. Statistical Models in S. Pacific Grove, CA.: Wadsworth & Brooks/Cole.
See Also
lm, model.frame, data.frame, ts
Examples
# data frame
x.data <- data.frame(c(1:3), c(1:2, NA), c(4:6) )
exc.x <- na.exclude(x.data)
na.action(exc.x)

try(lm(cost ~ age + type + car.age, data = Sdatasets::claims, weights = number, na.action = na.fail))

Package stats version 6.1.1-7
Package Index