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

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

    My guess is that this could be more elegantly solved in this way:

      m <- matrix(1:25, ncol = 5)
      m[c(1, 6, 13, 25)] <- NA
      df <- data.frame(m)
      library(dplyr) 
      df %>%
      filter_all(any_vars(is.na(.)))
      #>   X1 X2 X3 X4 X5
      #> 1 NA NA 11 16 21
      #> 2  3  8 NA 18 23
      #> 3  5 10 15 20 NA
    

提交回复
热议问题