This function identifies columns in a data frame that contain missing (NA) values.
identify_na_columns(data, print_output = TRUE, return_counts = FALSE)A data frame or tibble to inspect for missing values.
Logical. If TRUE, prints the columns with their NA counts. Defaults to TRUE.
Logical. If TRUE, returns a named vector with column names and their respective NA counts. If FALSE, returns a character vector of column names. Defaults to FALSE.
A character vector of column names with missing values, or a named vector with NA counts if return_counts = TRUE.
df <- data.frame(a = c(1, 2, NA), b = c(NA, 2, 3), c = c(1, 2, 3))
identify_na_columns(df)
#> Columns with NA values:
#> Column: a - NA count: 1
#> Column: b - NA count: 1
#> [1] "a" "b"
identify_na_columns(df, return_counts = TRUE)
#> Columns with NA values:
#> Column: a - NA count: 1
#> Column: b - NA count: 1
#> a b
#> 1 1