split_df: Split a single data frame into a list of data frames

View source: R/split_df.R

split_dfR Documentation

Split a single data frame into a list of data frames

Description

This function is the first part of the split-apply-combine workflow in handling multiple selection questions in the survey. In multi-select, participants are able to choose from a menu of choices provided. From a data perspective, multi-select responses are recorded in wide format where each column represents a single choice in a multi-select question. Related columns, i.e., those belonging to the same multi-select question, are grouped together using homogeneous "prefixes." This function takes a single data frame, divides it into subsets based on patterns in the column names (the "prefixes"), and returns a list containing the subsets.

Usage

split_df(df, patterns, weight)

Arguments

df

A data frame or data.table or tibble.

patterns

A character vector of "prefixes" for selecting columns in df.

weight

A single string of the weighting variable.

Value

A list of data frames, each of which is a data.table object.

See Also

apply_topline_multiselect() for vectorized topline generation for multiple selection questions and combine_topline_multiselect() for combining the multiselect toplines.

Examples


# Vector of patterns
patterns <- c("prefix_1", "predix_2", ...)

# List of data.tables
list_df <- split_df(df, patterns, "weight_var")


YangWu1227/citizenr documentation built on June 18, 2022, 12:17 p.m.