Find Complete Cases of Observations

DESCRIPTION:

Return a logical vector indicating which cases are complete, i.e., have no missing values. Cases are defined row-wise across an arbitrary collection of vectors, matrices and data frames.

USAGE:

complete.cases(x, ...)

ARGUMENTS:

x, ...
a collection of vectors, matrices and data frames. Only the first argument, x is required. All the arguments must have the same number of rows, or in the case of vectors, the same number of elements.

VALUE:

a logical vector specifying which observations or rows do not have any missing values across the entire collection.

SEE ALSO:

, , .

EXAMPLES:

# Make up a data set with missing values:
y <- ethanol[, 1]  # response variable
y[c(19, 23, 29, 31)] <- NA
x <- ethanol[, -1] # x is the model matrix
x[c(37, 41, 43, 47),] <- NA

all(complete.cases(y) != is.na(y))  # Should be TRUE

ok <- complete.cases(y, x)
sum(!ok)  # Should be 8