Learn R Programming

crunch (version 1.18.0)

combine: Combine categories or responses

Description

Combine categories or responses

Usage

combine(variable, combinations = list(), ...)

Arguments

variable

Categorical, Categorical Array, or Multiple Response variable

combinations

list of named lists containing (1) "categories": category ids or names for categorical types, or for multiple response, "responses": subvariable names, aliases, or positional indices; (2) a "name" for the new category or response; and (3) optionally, other category ("missing", "numeric_value") or subvariable ("alias", "description") attributes. If combinations is omitted, the resulting variable will essentially be a copy (but see link{copy} for a more natural way to do that, if desired).

...

Additional variable metadata for the new derived variable

Value

A VariableDefinition that will create the new comined-category or -response derived variable. Categories/responses not referenced in combinations will be appended to the end of the combinations.

Examples

Run this code
# NOT RUN {
ds$fav_pet2 <- combine(ds$fav_pet, name="Pets (combined)",
    combinations=list(list(name="Mammals", categories=c("Cat", "Dog")),
                      list(name="Reptiles", categories=c("Snake", "Lizard"))))
ds$pets_owned2 <- combine(ds$allpets, name="Pets owned (collapsed)",
    combinations=list(list(name="Mammals", responses=c("Cat", "Dog"))))
# }

Run the code above in your browser using DataLab