Learn R Programming

liver (version 1.19)

one.hot: One Hot Encoder

Description

One-Hot-Encode unordered factor columns of a data.frame, matrix, or data.table, using the mltools::one_hot() mltools::one_hot function.

Usage

one.hot(data, cols = "auto", sparsifyNAs = FALSE, naCols = FALSE, 
                   dropCols = TRUE, dropUnusedLevels = FALSE)

Arguments

data

a numerical vector, matrix, data.frame, or data.table.

cols

a character vector of column names or indices to one-hot-encode. If "auto", all unordered factor columns will be one-hot-encoded.

sparsifyNAs

a logical value indicating whether to converte NAs to 0s.

naCols

a logical value indicating whether to create a separate column for NAs.

dropCols

a logical value indicating whether to drop the original columns which are one-hot-encoded.

dropUnusedLevels

a logical value indicating whether to drop unused factor levels.

Author

Reza Mohammadi a.mohammadi@uva.nl and Kevin Burke kevin.burke@ul.ie

See Also

scaler

Examples

Run this code
data(risk)
str(risk)

risk_oh <- one.hot(risk, cols = "auto")
str(risk_oh)

Run the code above in your browser using DataLab