fastDummies (version 0.1.1)

fastDummy: Fast creation of dummy variables

Description

Fast creation of dummy variables

Usage

fastDummy(dataset, select.columns = NULL, ignore.columns = NULL,
  remove.original = TRUE, dummy.columns.only = FALSE,
  remove.first.dummy = FALSE, return.type = "data.table")

Arguments

dataset

data.table or data.frame

select.columns

Vector of column names that you want to create dummy variables from. Default uses all character or factor columns.

ignore.columns

Vector of column names to ignore. Default ignores all numeric columns.

remove.original

Removes the columns used to make dummy variables. Columns that are not used to make dummy variables are not affected.

dummy.columns.only

Removes all columns that didn't create dummy columns (i.e. numeric columns).

remove.first.dummy

Removes the first dummy of every variable that only n-1 Dummies remain

return.type

Type of data you want back. Default is data.table (better for use with large data). Other options are data.frame or matrix.

Value

data.table, data.frame, or matrix depending on input for return.type. data.table is default.

Examples

Run this code
# NOT RUN {
data(dummies.example)
example <- fastDummy(dummies.example)

# Return data.frame
example <- fastDummy(dummies.example, return.type = "data.frame")

# Only keep created dummy columns
example <- fastDummy(dummies.example, dummy.columns.only = TRUE)

# Only keep SEX and RACE columns
example <- fastDummy(dummies.example, select.columns = c("Sex", "RACE"))

# Keep all except SEX column
example <- fastDummy(dummies.example, ignore.columns = "SEX")

# Removes the first dummy from every category. Avoids perfect
# multicollinearity issues in models.
example <- fastDummy(dummies.example, remove.first.dummy = TRUE)
# }

Run the code above in your browser using DataLab