View source: R/analysis_missing.R
analysis_missing | R Documentation |
This function analyzes missing values for specified scales within a data frame.
analysis_missing(dat, scale)
dat |
A data frame containing the dataset to be analyzed. |
scale |
A list of character vectors, where each list element contains the variable names corresponding to a scale within the dataset. |
A data frame summarizing the missing value analysis for each scale. The output includes:
missing
: The total number of missing values for each scale.
total
: The total number of observations expected for each scale.
p
: The proportion of missing values for each scale (missing / total
).
n cases
: The number of cases with at least one missing value within the scale.
p cases
: The proportion of cases with at least one missing value (n cases / total cases
).
n all cases
: The number of cases where all variables in the scale are missing.
p all cases
: The proportion of cases where all variables in the scale are missing (n all cases / total cases
).
is.na()
, apply()
# Example dataset
dat <- data.frame(
scale1_var1 = c(1, 2, NA, 4),
scale1_var2 = c(NA, 2, 3, 4),
scale2_var1 = c(1, NA, 3, 4),
scale2_var2 = c(NA, NA, NA, 4)
)
# Define scales
scales <- list(
scale1 = c("scale1_var1", "scale1_var2"),
scale2 = c("scale2_var1", "scale2_var2")
)
# Analyze missing values
analysis_missing(dat, scales)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.