简体   繁体   中英

filter_all for !is.na() in R still yields missing values

I'm trying to use dplyr's filter_all() to yield all rows that do not have any missing data. I'm using dplyr's built in starwars dataset. When I use this code to yield that does have any missing values, it works seamlessly:

 library(dplyr)
 data("starwars")

rows_with_NAs <- starwars %>%
  filter_all(any_vars(is.na(.)))

However, if I try to find the rows that do not have any missing values with this code:

rows_without_NAs <- starwars %>%
  filter_all(any_vars(!is.na(.)))

I still get rows with NAs.

head(rows_without_NAs)

Why is this and how could I fix this?

Thank you!

tidyr has the drop_na() operator for this.

library(tidyverse)

data("starwars")

rows_without_NAs <- starwars %>%
    drop_na()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM