Drop columns for which all values are NA

drop_all_na(df, grouping_cols = NULL)

Arguments

df

A valid R `object` for which the percentage of missing values is required.

grouping_cols

A character vector. If supplied, one can provide the columns by which to group the data.

Examples

test <- data.frame(ID= c("A","A","B","A","B"), Vals = c(rep(NA,4),2))
test2 <- data.frame(ID= c("A","A","B","A","B"), Vals = rep(NA, 5))
# drop columns where all values are NA
drop_all_na(test2)
#>   ID
#> 1  A
#> 2  A
#> 3  B
#> 4  A
#> 5  B
# drop NAs only if all are NA for a given group, drops group too.
drop_all_na(test, "ID")
#> # A tibble: 2 x 2
#>   ID     Vals
#>   <chr> <dbl>
#> 1 B        NA
#> 2 B         2