| one_hot_encode | R Documentation |
one_hot_encode rebuilds a categorical variable to a so-called 'one-hot vector'.
Within a sample (row) of a one-hot vector (matrix) each level of the variable is rebuild in the binary form (0|1,0|1,0|1,...).
one_hot_encode(x, ordered = FALSE)
x |
A vector with values (levels) of a categorical variable. |
ordered |
A logical value indicating whether the factor levels of |
An unordered encoding creates an indicator matrix with the value 1 only for the given level of x and 0 for all other levels.
In opposite, an ordered encoding assumes an intrinsic order of all levels whereby a given level automatically means reaching and exceeding all previous levels.
In that case, all previous levels are also encoded with value 1.
A matrix with all levels as columns with either 0 or 1 values.
one_hot_decode, sparse_encode.
Other Dummifying:
append_rows(),
dummify(),
dummify_multilabel(),
effectcoding(),
one_hot_decode(),
remove_columns(),
resample_imbalanced(),
sparse_encode()
x <- factor(sample(lvls <- c("dog", "cat", "mouse"), 10, TRUE), levels = lvls)
one_hot_encode(x)
one_hot_encode(x, ordered = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.