The grid_vars
function transforms binary grid survey questions into a longer format,
enabling comparisons across different variables or groups. It supports optional grouping
and weighting.
Arguments
- data
A data frame containing survey data.
- vars
A list mapping original column names to new variable names. This is required and allows multiple variables. For example,
list(Q1a = "Art", Q1b = "Automobiles")
.- group
An optional variable for comparing across groups. Only one group can be specified.
- weight
An optional variable containing weight factors for the analysis.
Value
A data frame in a long format, with each row representing a response to a binary grid question. The data frame includes frequencies and optionally percentages if groups and/or weights are specified.
Details
The function first converts specified binary grid questions into a long format using
tidyr::pivot_longer
. It then uses grp_freq
to calculate frequencies and, if
applicable, percentages for each question-response pair. This allows for an in-depth
analysis of binary grid survey questions, especially when combined with group and weight parameters.
Examples
if (FALSE) { # \dontrun{
# Example: Convert grid questions to long format and analyze by gender
vars <- list(Q1a = "Art", Q1b = "Automobiles", Q1c = "Birdwatching")
df <- grid_vars(dataset, vars = vars, group = "gender", weight = "wgtvar")
} # }