powered by
One-Hot-Encode unordered factor columns of a data.frame, matrix, or data.table, using the mltools::one_hot() mltools::one_hot function.
mltools::one_hot()
one.hot(data, cols = "auto", sparsifyNAs = FALSE, naCols = FALSE, dropCols = TRUE, dropUnusedLevels = FALSE)
a numerical vector, matrix, data.frame, or data.table.
vector
matrix
data.frame
data.table
a character vector of column names or indices to one-hot-encode. If "auto", all unordered factor columns will be one-hot-encoded.
"auto"
a logical value indicating whether to converte NAs to 0s.
a logical value indicating whether to create a separate column for NAs.
a logical value indicating whether to drop the original columns which are one-hot-encoded.
a logical value indicating whether to drop unused factor levels.
Reza Mohammadi a.mohammadi@uva.nl and Kevin Burke kevin.burke@ul.ie
scaler
data(risk) str(risk) risk_oh <- one.hot(risk, cols = "auto") str(risk_oh)
Run the code above in your browser using DataLab