Learn R Programming

onehot (version 0.1.1)

onehot: Onehot encode a data.frame

Description

Onehot encode a data.frame

Usage

onehot(data, stringsAsFactors = FALSE, addNA = FALSE, max_levels = 10)

Arguments

data
data.frame to convert factors into onehot encoded columns
stringsAsFactors
if TRUE, converts character vectors to factors
addNA
if TRUE, adds NA to factors as a level
max_levels
maximum number of levels to onehot encode per factor variable. Factors with levels exceeding this number will be skipped.

Value

a onehot object descrbing how to transform the data

Examples

Run this code
data(iris)
encoder <- onehot(iris)

## add NAs to factors
encoder <- onehot(iris, addNA=TRUE)

## Convert character fields to factrs
encoder <- onehot(iris, stringsAsFactors=TRUE)

## limit which factors are onehot encoded
encoder <- onehot(iris, max_levels=5)

Run the code above in your browser using DataLab