one.hot: One Hot Encoder

View source: R/one.hot.R

one.hotR Documentation

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(s)

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

See Also

scaler

Examples

data(risk)
str(risk)

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

liver documentation built on April 3, 2025, 10:51 p.m.