Learn R Programming

logitr (version 0.1.0)

dummyCode: Creates dummy-coded variables.

Description

This function adds dummy-coded variables to a data frame based on a vector of column names.

Usage

dummyCode(df, vars)

Arguments

df

A data frame.

vars

The variables in the data frame for which you want to create new dummy coded variables.

Value

A a dataframe with new dummy-coded variables added.

Examples

Run this code
# NOT RUN {
# Create an example data frame:
df <- data.frame(
    animal   = c("dog", "goldfish", "bird", "dog", "goldfish"),
    numLegs  = c(4, 0, 2, 4, 0),
    lifeSpan = c(10, 10, 5, 10, 10))

# Create dummy coded variables for the variables "animal" and "numLegs":
df_dummy <- dummyCode(df, vars = c("animal", "numLegs"))
df_dummy
# }

Run the code above in your browser using DataLab