Created
July 26, 2021 14:41
-
-
Save ayoskovich/43f949b8f527e6f5c1910d8e56e8ffdd to your computer and use it in GitHub Desktop.
Filter based on data nullness (?) across many columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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