r, does not equal, nas are not included

后端 未结 2 918
猫巷女王i
猫巷女王i 2021-01-22 04:19

I\'m trying to filter my data to leave out certain values. The problem is that I want to include the NAs. When I use the does not equal, \"!=\", operator, the NAs are also rem

2条回答
  •  臣服心动
    2021-01-22 05:27

    NA is never equal to anything.

    NA == NA # NA, not TRUE
    

    @bouncyball's would be the recommended solution, if you want to check if two values or variables are really the same you can use identical :

    df %>% filter(!sapply(a, identical, "B"))
    

    or using library purrr

    df %>% filter(!map_lgl(a, identical, "B"))
    

提交回复
热议问题