Learn R Programming

REAT (version 3.0.3)

to.dummy: Creating dummy variables

Description

This function creates a dataset of dummy variables based on an input character vector.

Usage

to.dummy(x)

Arguments

x

A character vector

Value

A data.frame with dummy variables corresponding to the levels of the input variable.

Details

This function transforms a character vector x with \(c\) characteristics to a set of \(c\) dummy variables whose column names corresponding to these characteristics marked with “_DUMMY”.

References

Greene, W. H. (2012): “Econometric Analysis”. 7th edition. Harlow : Pearson.

Examples

Run this code
# NOT RUN {
charvec <- c("Peter", "Paul", "Peter", "Mary", "Peter", "Paul")
# Creates a vector with three names (Peter, Paul, Mary)
to.dummy(charvec)
# Returns a data frame with 3 dummy variables
# (Mary_DUMMY, Paul_DUMMY, Peter_DUMMY)
# }

Run the code above in your browser using DataLab