Learn R Programming

weights (version 1.0.4)

dummify: Separate a factor into separate dummy variables for each level.

Description

dummify creates a matrix with columns signifying separate dummy variables for each level of a factor. The column names are the former levels of the factor.

Usage

dummify(x, show.na=FALSE, keep.na=FALSE)

Arguments

x

x is a factor the researcher desires to split into separate dummy variables.

show.na

If show.na is 'TRUE', output will include a column idicating the cases that are missing.

keep.na

If keep.na is 'TRUE', output vectors will have "NA"s for cases that were originally missing.

Value

dummify returns a matrix with a number of rows equal to the length of x and a number of columns equal to the number of levels of x.

Examples

Run this code
# NOT RUN {
data("anes04")

anes04$agecats <- cut(anes04$age, c(17, 25,35,45,55,65, 99))
levels(anes04$agecats) <- c("age1824", "age2534", "age3544",
          "age4554", "age5564", "age6599")

agedums <- dummify(anes04$agecats)
table(anes04$agecats)
summary(agedums)
# }

Run the code above in your browser using DataLab