Useful things R
Filter rows in and out with dplyr
Multiple values (same column) in and out
-
%in% c("x", "y")
for values -
!colname
for negation
Multiple columns (some values) in and out
Keep/Drop rows that have ALL NA values in all columns
# Filter rows that have only NA values in all columns
cols_allNA <- starwars %>%
filter(if_all(everything(), is.na)) # 0
# or drop them
# Drop rows that have NA values in all columns
cols_noneNA <- starwars %>%
filter(!if_all(everything(), is.na)) # 87
Drop rows that have ANY NA values in all columns
# Filter rows that have only NA values in all columns
cols_anyNA <- starwars %>%
filter(!if_any(everything(), is.na)) # 58
Keep/drop rows that have ALL NA values in some columns
# Filter rows that have only NA values in all columns whose name ....
spec_col_allNA <- starwars %>%
filter(if_all(starts_with("h"), is.na)) # 0
# filter(!if_all(starts_with("h"), is.na)) # 0