Remove rows with all or some NAs (missing values) in data.frame

后端 未结 16 1646
日久生厌
日久生厌 2020-11-21 05:49

I\'d like to remove the lines in this data frame that:

a) contain NAs across all columns. Below is my example data frame.



        
16条回答
  •  别跟我提以往
    2020-11-21 06:10

    Assuming dat as your dataframe, the expected output can be achieved using

    1.rowSums

    > dat[!rowSums((is.na(dat))),]
                 gene hsap mmul mmus rnor cfam
    2 ENSG00000199674    0   2    2    2    2
    6 ENSG00000221312    0   1    2    3    2
    

    2.lapply

    > dat[!Reduce('|',lapply(dat,is.na)),]
                 gene hsap mmul mmus rnor cfam
    2 ENSG00000199674    0   2    2    2    2
    6 ENSG00000221312    0   1    2    3    2
    

提交回复
热议问题