One-hot Encoder

one_hot_encoder(data, feature, as_integer = FALSE)

Arguments

data

Input data frame

feature

Unquoted form of the feature/column to encode

as_integer

Whether the boolean should be converted to integer or not

Value

Data frame with encodeded feature column

Examples

set.seed(11) one_hot_encoder(iris[sample(1:150, 10),], Species)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species_setosa #> 34 5.5 4.2 1.4 0.2 TRUE #> 144 6.8 3.2 5.9 2.3 FALSE #> 113 6.8 3.0 5.5 2.1 FALSE #> 37 5.5 3.5 1.3 0.2 TRUE #> 60 5.2 2.7 3.9 1.4 FALSE #> 118 7.7 3.8 6.7 2.2 FALSE #> 140 6.9 3.1 5.4 2.1 FALSE #> 62 5.9 3.0 4.2 1.5 FALSE #> 85 5.4 3.0 4.5 1.5 FALSE #> 93 5.8 2.6 4.0 1.2 FALSE #> Species_versicolor Species_virginica #> 34 FALSE FALSE #> 144 FALSE TRUE #> 113 FALSE TRUE #> 37 FALSE FALSE #> 60 TRUE FALSE #> 118 FALSE TRUE #> 140 FALSE TRUE #> 62 TRUE FALSE #> 85 TRUE FALSE #> 93 TRUE FALSE