View source: R/generate_from_factor.R
| one_hot_encoder | R Documentation | 
Transform factor column into 0/1 columns with one column per values of the column.
one_hot_encoder(
  data_set,
  encoding = NULL,
  type = "integer",
  verbose = TRUE,
  drop = FALSE
)
| data_set | Matrix, data.frame or data.table | 
| encoding | Result of function  | 
| type | What class of columns is expected? "integer" (0L/1L), "numeric" (0/1), or "logical" (TRUE/FALSE), (character, default to "integer") | 
| verbose | Should the function log (logical, default to TRUE) | 
| drop | Should  | 
If you don't want to edit your data set consider sending copy(data_set) as an input.
Please be careful using this function, it will generate as many columns as there different values
in your column and might use a lot of RAM. To be safe, you can use parameter
min_frequency in build_encoding.
data_set edited by reference with new columns.
data(tiny_messy_adult)
# Compute encoding
encoding <- build_encoding(tiny_messy_adult, cols = c("marital", "occupation"), verbose = TRUE)
# Apply it
tiny_messy_adult <- one_hot_encoder(tiny_messy_adult, encoding = encoding, drop = TRUE)
# Apply same encoding to adult
data(adult)
adult <- one_hot_encoder(adult, encoding = encoding, drop = TRUE)
# To have encoding as logical (TRUE/FALSE), pass it in type argument
data(adult)
adult <- one_hot_encoder(adult, encoding = encoding, type = "logical", drop = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.