Remove rows where all variables are NA using dplyr

后端 未结 6 1698
北荒
北荒 2020-12-08 07:18

I\'m having some issues with a seemingly simple task: to remove all rows where all variables are NA using dplyr. I know it can be done using base R (Re

6条回答
  •  长情又很酷
    2020-12-08 07:59

    Since dplyr 0.7.0 new, scoped filtering verbs exists. Using filter_any you can easily filter rows with at least one non-missing column:

    dat %>% filter_all(any_vars(!is.na(.)))
    

    Using @hejseb benchmarking algorithm it appears that this solution is as efficient as f4.

提交回复
热议问题