Summarizes missing values across user-defined scales in a data frame.

nice_missings_table(dat, scale, ...)

Arguments

dat

A data frame containing the data to be analyzed.

scale

A named list of character vectors. Each list element defines a scale by specifying variable names (column names in dat) belonging to that scale.

...

Further arguments passed to the nice_table() function for formatting the output.

Value

A data frame summarizing the missing value statistics for each scale with the following columns:

Missing

Number and percentage of missing values across variables in the scale.

Complete cases

Number and percentage of cases with no missing value in the scale.

All missing cases

Number and percentage of cases where all scale variables are missing.

Details

This function is useful for assessing the extent of missing data within specific scales of a dataset. It provides insights into both the overall missings and the distribution of missing values across cases for each defined scale.

Author

Jürgen Wilbert

Examples

dat <- data.frame(
  scale1_var1 = c(1, 2, NA, 4,NA),
  scale1_var2 = c(NA, 2, NA, 4,NA),
  scale2_var1 = c(1, NA, 3, 4, 1),
  scale2_var2 = c(NA, NA, NA, 4, 1)
)

scales <- list(
  scale1 = c("scale1_var1", "scale1_var2"),
  scale2 = c("scale2_var1", "scale2_var2")
)

nice_missings_table(dat, scales)
Missing
Complete cases
All missing cases
n % n % n %
scale1 5 50 2 40 2 40
scale2 4 40 2 40 1 20