R: Find Complete Cases (original) (raw)

complete.cases {stats} R Documentation

Description

Return a logical vector indicating which cases are complete, i.e., have no missing values.

Usage

complete.cases(...)

Arguments

... a sequence of vectors, matrices and data frames.

Value

A logical vector specifying which observations/rows have no missing values across the entire sequence.

Note

A current limitation of this function is that it uses low level functions to determine lengths and missingness, ignoring the class. This will lead to spurious errors when some columns have classes with [length](../../base/html/length.html) or [is.na](../../base/html/NA.html)methods, for example "[POSIXlt](../../base/html/DateTimeClasses.html)", as described in PR#16648.

See Also

[is.na](../../base/html/NA.html),[na.omit](../../stats/help/na.omit.html),[na.fail](../../stats/help/na.fail.html).

Examples

x <- airquality[, -1] # x is a regression design matrix
y <- airquality[,  1] # y is the corresponding response

stopifnot(complete.cases(y) != is.na(y))
ok <- complete.cases(x, y)
sum(!ok) # how many are not "ok" ?
x <- x[ok,]
y <- y[ok]

[Package _stats_ version 4.6.0 Index]