dummy.code: Create dummy coded variables

Description Usage Arguments Details Value Author(s) Examples

Description

Given a variable x with n distinct values, create n new dummy coded variables coded 0/1 for presence (1) or absence (0) of each variable. A typical application would be to create dummy coded college majors from a vector of college majors. By default, NA values of x are returned as NA (added 10/20/17)

Usage

1
dummy.code(x,na.rm=TRUE)

Arguments

x

A vector to be transformed into dummy codes

na.rm

If TRUE, return NA for all codes with NA in x

Details

When coding demographic information, it is typical to create one variable with multiple categorical values (e.g., ethnicity, college major, occupation). dummy.code will convert these categories into n distinct dummy coded variables.

If using dummy coded variables as predictors, remember to use n-1 variables.

Value

A matrix of dummy coded variables

Author(s)

William Revelle

Examples

1
2
3
new <- dummy.code(sat.act$education)
new.sat <- data.frame(new,sat.act)
round(cor(new.sat,use="pairwise"),2)

psych documentation built on May 7, 2018, 1:04 a.m.