Skip to content

Instantly share code, notes, and snippets.

@ayoskovich
Created July 26, 2021 14:41
Show Gist options
  • Save ayoskovich/43f949b8f527e6f5c1910d8e56e8ffdd to your computer and use it in GitHub Desktop.
Save ayoskovich/43f949b8f527e6f5c1910d8e56e8ffdd to your computer and use it in GitHub Desktop.
Filter based on data nullness (?) across many columns
howMany <- function(x){ length(unique(x))}
allSame <- function(x){ length(unique(x)) == 1}
df %>%
# Keep rows that have values for all columns that contain '-'
filter(if_all(matches('-'), ~ !is.na(.))) %>%
rowwise() %>%
# Use c_across to work with rowwise
mutate(num = howMany(c_across(matches('-'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment