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

后端 未结 16 1608
日久生厌
日久生厌 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:16

    delete.dirt <- function(DF, dart=c('NA')) {
      dirty_rows <- apply(DF, 1, function(r) !any(r %in% dart))
      DF <- DF[dirty_rows, ]
    }
    
    mydata <- delete.dirt(mydata)
    

    Above function deletes all the rows from the data frame that has 'NA' in any column and returns the resultant data. If you want to check for multiple values like NA and ? change dart=c('NA') in function param to dart=c('NA', '?')

提交回复
热议问题