na.fail {base} | R Documentation

## Handle Missing Values in Objects

### Description

These generic functions are useful for dealing with `NA`s 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.

### Usage

    na.fail(object)
    na.omit(object)

### Arguments

`object` | an R object, typically a data frame

### Details

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"`.

### See Also

`na.action`, `options(na.action=..)` for setting ``NA actions'', and `lm` and `glm` for functions using these.

### Examples

    DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA))
    na.omit(DF)
    m <- as.matrix(DF)
    na.omit(m)
    na.fail(DF)#> Error: missing values in ..

    options("na.action")

[Package Contents]