onehot: Onehot encode a data.frame

Description Usage Arguments Value Examples

View source: R/predict.R

Description

Onehot encode a data.frame

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

Example output



onehot documentation built on May 2, 2019, 9:15 a.m.

Related to onehot in onehot...