Find names of columns which contain missing values

前端 未结 3 1078
忘掉有多难
忘掉有多难 2020-12-05 03:59

I want to find all the names of columns with NA or missing data and store these column names in a vector.

# create matrix
a <- c(1,2,3,4,5,N         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-05 05:03

    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)))))

提交回复
热议问题