Skip to content

Instantly share code, notes, and snippets.

@eddjberry
Last active February 19, 2019 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddjberry/6f8a55a58af061883a0ef5196f37e6c4 to your computer and use it in GitHub Desktop.
Save eddjberry/6f8a55a58af061883a0ef5196f37e6c4 to your computer and use it in GitHub Desktop.
Using filter_at to remove rows with some or all NAs for a specified set of columns. If we wanted to do this for all columns we could use janitor::remove_empty('rows')
# create some data
(df <- data_frame(x = 1:2,
y = c(NA, NA),
z = c(NA, 3)))
# remove rows where either col y or z contain NA
# i.e. keep rows where all variables are not NA
df %>%
filter_at(vars(y:z), all_vars(!is.na(.)))
# remove rows where both cols y and z contain NA
# i.e. keep rows where any variable is not NA
df %>%
filter_at(vars(y:z), any_vars(!is.na(.)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment