Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

interactVariables

Create a variable by interacting categorical variables


Description

interactVariables takes two or more variables and creates a new one that is the cartesian product expansion of their unique values. For example, if we cross ethnicity (with 2 categories) and race (with 4 categories), the new variable would have 8 valid categories (e.g. black:hispanic, white:hispanic, black:non-hispanic, etc.) and 7 categories where at least one of the variables is missing (e.g. white:No Data).

Usage

interactVariables(..., name, sep = ":")

Arguments

...

a sequence of categorical variables to make an interaction from as well as other properties to pass about the case variable (i.e. alias, description)

name

a character to use as the name for the interaction variable

sep

a character to separate the values of the individual variables (default: :)

Value

A VariableDefinition that creates the new interaction variable.

Examples

## Not run: 
ds$ethn_race <- interactVariables(
  ds$ethnicity, ds$race, name = "Interaction of ethnicity and race"
)

## End(Not run)

crunch

Crunch.io Data Tools

v1.28.0
LGPL (>= 3)
Authors
Greg Freedman Ellis [aut, cre], Jonathan Keane [aut], Mike Malecki [aut], Neal Richardson [aut], Gordon Shotwell [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.