These generic functions are useful for dealing with
in e.g., data frames.
na.fail 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.
na.fail(object, ...) 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).
na.omit removes cases, the row numbers of the cases form the
"na.action" attribute of the result, of class
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
na.exclude is used the residuals and predictions are padded to
the correct length by inserting
NAs for cases omitted by
Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.
options with argument
na.action for setting NA actions;
glm for functions using these.
na.contiguous as alternative for time series.
DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA)) na.omit(DF) m <- as.matrix(DF) na.omit(m) stopifnot(all(na.omit(1:3) == 1:3)) # does not affect objects with no NA's try(na.fail(DF)) #> Error: missing values in ... options("na.action")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.