This set of functions is designed to assign standard column metadata attributes to store in a survey database.
You can use
assign_col_attribute()for assigning any named attribute to a column.But it is recommended to use specific attribute functions for clarity:
assign_col_module()for marking the question module.assign_col_response_type()for defining the response type.assign_col_mr_group()andassign_col_mr_group_auto()for marking multiple response groups. The 'auto' function is not guaranteed to work correctly every time, but you may find it convenient to use it in conjunction with the normal one.
Use
get_dict_for_db()to review all assigned attributes.
Usage
assign_col_attribute(data, attribute, value, ...)
assign_col_module(data, module, ...)
assign_col_response_type(
data,
response_type = c("multiple_response", "single_response", "rank", "treatment",
"open-ended"),
...
)
assign_col_mr_group(data, mr_group, ...)
assign_col_mr_group_auto(data)
get_dict_for_db(data)Arguments
- data
A data frame to be marked
- attribute
String. The attribute name to assign.
- value
String. The value to assign to the attribute for selected columns.
- ...
A set of column selection expressions, compatible with
dplyr::select().- module
String. Name of the survey module, such as "Demographics" or "Questionnaire".
- response_type
One of the pre-determined question response types. Valid options are "multiple_response", "single_response", "rank", "treatment", "open-ended".
- mr_group
String. Specifies the common prefix for columns belonging to the same multiple response group.
Examples
data_marked <-
example_survey_data_climate |>
assign_col_module("demographics", XIDEO, XPARTY7) |>
assign_col_module("questionnaire", starts_with("Q")) |>
assign_col_response_type("multiple_response", starts_with("Q17_Q16")) |>
assign_col_response_type("single_response", XIDEO, XPARTY7, Q11) |>
assign_col_mr_group("Q17_Q16", starts_with("Q17_Q16"))
# check the marking
get_dict_for_db(data_marked)
#> # A tibble: 9 × 5
#> question_id question_text module response_type mr_group
#> <chr> <chr> <chr> <chr> <chr>
#> 1 response_id NA NA NA NA
#> 2 weight Case weight NA NA NA
#> 3 XIDEO Ideology demog… single_respo… NA
#> 4 XPARTY7 Party ID demog… single_respo… NA
#> 5 Q11 Overall, do you support or oppose e… quest… single_respo… NA
#> 6 Q17_Q16a [The federal government] [Apart fro… quest… multiple_res… Q17_Q16
#> 7 Q17_Q16b [Your state government] [Apart from… quest… multiple_res… Q17_Q16
#> 8 Q17_Q16c [Individual wealthy business leader… quest… multiple_res… Q17_Q16
#> 9 Q17_Q16d [Climate scientists and other unive… quest… multiple_res… Q17_Q16