onehot {onehot}R Documentation

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

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)

[Package onehot version 0.1.1 Index]