Skip to content

Instantly share code, notes, and snippets.

@briandk
Last active August 9, 2026 04:13
Show Gist options
  • Select an option

  • Save briandk/c254a40064f1845d9b40a71726b56e3a to your computer and use it in GitHub Desktop.

Select an option

Save briandk/c254a40064f1845d9b40a71726b56e3a to your computer and use it in GitHub Desktop.
library(dplyr)
# The full `starwars` tibble should have 87 rows ----
nrow(starwars)
# `filter()`-ing on it Works Predictably ----
## This should result in a 1-row tibble with Jabba the Hutt
filter(starwars, !is.na(mass), mass > 1000)
## And we can check the number of rowsto confirm it's 1
filter(starwars, !is.na(mass), mass > 1000) |>
nrow()
# But I'm having problems with `filter_out()` ----
## This should result in a 1-row tibble with Jabba the Hutt.
## All I've done is flip the conditions from the original `filter()`
## Instead, it returns the full starwars tibble
filter_out(starwars, is.na(mass), mass < 1000)
# And again, we can check the number of rows and see it's 87
filter_out(starwars, is.na(mass), mass < 1000) |>
nrow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment