stats (version 3.5.0) Handle Missing Values in Objects


These generic functions are useful for dealing with NAs in e.g., data frames. returns the object if it does not contain any missing values, and signals an error otherwise. na.omit returns the object with incomplete cases removed. na.pass returns the object unchanged.

Usage, …)
na.omit(object, …)
na.exclude(object, …)
na.pass(object, …)



an R object, typically a data frame

further arguments special methods could require.


At present these will handle vectors, matrices and data frames comprising vectors and matrices (only).

If na.omit removes cases, the row numbers of the cases form the "na.action" attribute of the result, of class "omit".

na.exclude differs from na.omit only in the class of the "na.action" attribute of the result, which is "exclude". This gives different behaviour in functions making use of naresid and napredict: when na.exclude is used the residuals and predictions are padded to the correct length by inserting NAs for cases omitted by na.exclude.


Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.

See Also

na.action; options with argument na.action for setting NA actions; and lm and glm for functions using these. na.contiguous as alternative for time series.


Run this code
DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA))
m <- as.matrix(DF)
stopifnot(all(na.omit(1:3) == 1:3))  # does not affect objects with no NA's
try(   #> Error: missing values in ...

# }

Run the code above in your browser using DataLab