| combine_checkboxes | R Documentation |
Takes a group of checkbox-style variables, have a common prefix and numeric suffixes representing options, and combines them into a single list column where each element is a vector of selected options (numbers).
This function expects the input data to include participant_id and
session_id columns, which are used to group responses. For each participant
and session, it collects all checkbox numbers that were selected as a single
list. The resulting column can be renamed via the name parameter.
combine_checkboxes(data, var_basename, var_sep = "___", name = NULL)
data |
tbl. Data frame containing the participant responses. |
var_basename |
character of length 1. The base name of the checkbox field. |
var_sep |
character of length 1. The string separating the base name
of the checkbox and the checkbox value. Default is |
name |
character of length 1 or |
tbl. The input data frame with an additional column containing a list of integers corresponding to the selected checkbox options for each participant and session.
# Example data
dat <- tibble::tibble(
participant_id = c(1, 1, 2),
session_id = c(1, 2, 1),
q1___1 = c(1, NA, 0),
q1___2 = c(0, 1, 1),
q1___3 = c(NA, NA, 0)
)
# Combine q1 checkboxes into a single list column
combine_checkboxes(dat, var_basename = "q1")
# Combine and rename the output column
combine_checkboxes(dat, var_basename = "q1", name = "q1_combined")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.