crunch_reorder_sr() reorders a Single Response variable on
Crunch. crunch_reorder_mr() reorders a Multiple Response variable on
Crunch. Both of the functions are silent.
Usage
crunch_reorder_mr(data, var_alias, .order_by, decreasing = TRUE)
crunch_reorder_sr(data, var_alias, decreasing = TRUE)Arguments
- data
A Crunch dataset object.
crunch::loadDataset().- var_alias
Character. The
crunch::alias()of the variable to reorder.- .order_by
Character. The name of the field to order by (for MR variables).
- decreasing
Logical. The order of arrangement. Default to
TRUE.
Value
The functions are silent. As a result they modify order of variable
in Crunch dataset. To check the order of variable/s you can use
crunch::categories().
Examples
if (FALSE) { # \dontrun{
library("crunch")
name <- "Examples/Sample Dataset for functions"
ds <- loadDataset(name);unlock(ds)
# Single Response Variables ------------------------------------------------
crunch_reorder_sr(data = ds, var_alias = "s_ethnicity", decreasing = FALSE)
# Check if order changes
categories(ds$s_ethnicity)
crunch_reorder_sr(data = ds, var_alias = "s_ethnicity", decreasing = TRUE)
# Check if order changes
categories(ds$s_ethnicity)
# Multiple Response Variables ----------------------------------------------
crunch_reorder_mr(data = ds, var_alias = "m6_buy_", .order_by = "Selected")
# Check that the order of categories is changed
crtabs(~m6_buy_, ds)
crunch_reorder_mr(
data = ds, var_alias = "m6_buy_", .order_by = "Selected", decreasing = FALSE
)
# Check that the order of categories is changed
crtabs(~m6_buy_, ds)
} # }