J.S*_*ree 2 filtering r filter na dplyr
我正在尝试使用 dplyr 的 filter_all() 来生成没有任何缺失数据的所有行。我正在使用 dplyr 内置的 starwars 数据集。当我使用此代码生成确实有任何缺失值的代码时,它可以无缝地工作:
 library(dplyr)
 data("starwars")
rows_with_NAs <- starwars %>%
  filter_all(any_vars(is.na(.)))
但是,如果我尝试使用此代码查找没有任何缺失值的行:
rows_without_NAs <- starwars %>%
  filter_all(any_vars(!is.na(.)))
我仍然得到带有 NA 的行。
head(rows_without_NAs)
为什么会这样,我该如何解决?
谢谢!
tidyr有drop_na()运营商。
library(tidyverse)
data("starwars")
rows_without_NAs <- starwars %>%
    drop_na()