I want to find all the names of columns with NA or missing data and store these column names in a vector.
NA
# create matrix a <- c(1,2,3,4,5,N
If you have a data frame with non-numeric columns, this solution is more general (building on previous answers):
R 3.1 +
names(which(sapply(mymatrix, anyNA)))
or
names(which(sapply(mymatrix, function(x) any(is.na(x)))))