Survey scales (education, Likert, frequency, ...) have a natural order that is
tedious to retype as levels = c(...) every time. Register an order once,
link it to the variable names and/or column prefixes it applies to, and the
tabulating helpers (e.g. calc_percentage()) will look it up and apply it
automatically. Persist your orders in a profile with save_ezrsurvey_profile().
Arguments
- name
Short name for the order (e.g.
"education").- levels
Character vector of the levels in ascending order.
- vars
Optional exact column names this order applies to (e.g.
"demo_edu").- prefixes
Optional column-name prefixes this order applies to (e.g.
"edu_"). A variable matches if its name starts with any prefix.- overwrite
Overwrite an existing order of the same name. Default
TRUE.
Details
An order links a set of levels to the columns it applies to, by exact name
(vars) and/or by prefix (prefixes). Once registered, calc_percentage(),
calc_percentage_multi() and crosstab() look it up automatically (via
order_for()) whenever you don't pass an explicit levels/sort, so a
question always comes out in the right order without retyping it. Register
interactively for the session, or store orders in a profile with
save_ezrsurvey_profile() so they load every session.
See also
order_for(), apply_order(), list_orders(),
register_order_presets().
Other config:
apply_order(),
edit_ezrsurvey_profile(),
ezrsurvey_options(),
ezrsurvey_profile_paths(),
get_dataset(),
get_order(),
list_orders(),
load_ezrsurvey_profile(),
order_for(),
register_order_presets(),
remove_order(),
reset_ezrsurvey_options(),
save_ezrsurvey_profile(),
use_dataset(),
use_ezrsurvey_profile()
Examples
register_order(
"education",
levels = c("Primary or less", "Lower secondary", "Upper secondary",
"Short-cycle tertiary", "Bachelor or equivalent",
"Master or equivalent", "Doctoral or equivalent"),
vars = "demo_edu"
)
calc_percentage(podracing_survey, demo_edu) # rows now in education order
#> # A tibble: 7 × 3
#> demo_edu n pct
#> <ord> <int> <dbl>
#> 1 Primary or less 42 4
#> 2 Lower secondary 111 11
#> 3 Upper secondary 295 30
#> 4 Short-cycle tertiary 123 13
#> 5 Bachelor or equivalent 244 25
#> 6 Master or equivalent 122 13
#> 7 Doctoral or equivalent 35 4
remove_order("education")
