I get this reproducible example from Working with names and expressions in your tidy eval code - Lionel Henry
library(tidyverse)
starwars %>% filter(height < 200, gender == "male") %>% dim()
## [1] 50 13
starwars[(starwars$height < 200 & starwars$gender == "male"),] %>% dim()
## [1] 56 13
Seemingly, filter(height < 200, gender == "male")
is not equal to
(starwars$height < 200 & starwars$gender == "male")
.
starwars2 <-
starwars %>%
mutate(index = row_number())
starwars2[(starwars2$height < 200 &
starwars2$gender == "male"),] %>%
anti_join(starwars2 %>%
filter(height < 200, gender == "male"), by = "index")
## # A tibble: 6 x 14
## name height mass hair_color skin_color eye_color birth_year gender homeworld
## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## 2 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## 3 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## 4 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## 5 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## 6 <NA> NA NA <NA> <NA> <NA> NA <NA> <NA>
## # ... with 5 more variables: species <chr>, films <list>, vehicles <list>,
## # starships <list>, index <int>
So, (starwars2$height < 200 & starwars2$gender == "male")
does not
deal with all NA rows? Is there any argument in [...]
to make
(starwars2$height < 200 & starwars2$gender == "male")
equal to
filter(height < 200, gender == "male")
.