Find columns with all missing values

后端 未结 8 484
Happy的楠姐
Happy的楠姐 2020-12-09 08:42

I am writing a function, which needs a check on whether (and which!) column (variable) has all missing values (NA, ). The following is fr

8条回答
  •  被撕碎了的回忆
    2020-12-09 08:54

    To test whether columns have all missing values:

    apply(test1,2,function(x) {all(is.na(x))})
    

    To get which columns have all missing values:

      test1.nona <- test1[ , colSums(is.na(test1)) == 0]
    

提交回复
热议问题