Crunch allows you to create a new categorical variable by combining the categories of another variable. For instance, you might want to recode a categorical variable with three categories small, medium, and large to one that has just small and large.
1 2 3 4 5
Categorical, Categorical Array, or Multiple Response variable
list of named lists containing
Additional variable metadata for the new derived variable
Categorical and categorical array variables can have their
categories combined (by specifying
categories in the
argument). Multiple response variables can only have their responses (or
items) combined (by specifying
responses in the
Categorical array items are not able to be combined together (even by
dplyr users may experience a name conflict between
dplyr:: combine(). To avoid this, you can either explicitly use the
crunch:: prefix, or you can call
combineResponses(), provided for disambiguation.
VariableDefinition that will create the new combined-category or
-response derived variable. Categories/responses not referenced in
combinations will be
appended to the end of the combinations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
## 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"))) ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.