A helper function to transform data into a longer format in preparation for use in cata_code().
Arguments
- data
A data frame where rows are participants or participant by time combinations if
timeis specified.- id
The column in
datato uniquely identify each participant.- cols
<
tidy-select> The columns indataindicating the check-all-that-apply categories to combine. Endorsement of the category should be indicated by the same value (e.g., 1, "Yes") across all columns included here. Columns are typically dichotomous variables with the two values indicating endorsement or not, but this is not a requirement.- time
The column in
datafor the time variable; used to reshape longitudinal data with multiple observations for eachid.- names_to
Character. The name for the new column of category labels (i.e., names of the
colscolumns), which is passed topivot_longer().- values_to
Character. The name for the new column of responses (i.e., cell values in the
colscolumns), which is passed topivot_longer().- ...
Optional additional arguments passed to
pivot_longer().
Value
An object of the same type as data with one row for each id (by time, if specified) by response category combination.
Examples
data(sources_race)
cata_prep(data = sources_race, id = ID, cols = Black:White, time = Wave)