apply_topline_multiselect: Apply topline generation to a list of data frames

View source: R/apply_topline_multiselect.R

apply_topline_multiselectR Documentation

Apply topline generation to a list of data frames

Description

This function is the second part of the split-apply-combine workflow in handling multiple selection questions in the survey. It takes the result of split_df(). The caption argument can also be generated with the helper function.

Usage

apply_topline_multiselect(list_df, weight, caption, parent)

Arguments

list_df

A list of data frame objects.

weight

A single string of the weighting variable.

caption

A list of character vectors of captions for the toplines.

parent

A logical vector of booleans indicating whether df has a parent response column.

Value

A list containing two elements— result and error, which are lists in and of themselves. These two lists have the same structure and number of elements. The result is a list of list objects. One can think of each element in result as the output of a single run of generate_topline_multiselect(), if it suceeds. The error list captures all runs of generate_topline_multiselect() that have failed, returning the error messages. If all run fails, result will be a NULL list; on the other end, if no run fails, error will be a NULL list.

See Also

generate_topline_multiselect() for single topline generation for multiple selection questions, split_df() for splitting a single data frame into smaller subsets, 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")

# Apply topline generation to each element of 'list_df'
captions <- list(c("caption_parent", "caption_child"), "caption_2", ...)
parents <- c(TRUE, FALSE, ...)
results <- apply_topline_multiselect(list_df, "weight_var", captions, parents)


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