| fct_encode_one_hot | R Documentation |
fct_encode_one_hot() encodes a factor as a one-hot indicator matrix.
This matrix consists of length(x) rows and length(levels(x)) columns.
Every value in row i of the matrix is filled with 0L except for the
column that has the same name as x[[i]], which is instead filled with 1L.
fct_encode_one_hot(x)
x |
A factor.
|
The columns are returned in the same order as levels(x).
If x has names, the names are propagated onto the result as the row names.
An integer matrix with length(x) rows and length(levels(x))
columns.
fct_encode_one_hot(factor(letters))
fct_encode_one_hot(factor(letters[1:2], levels = letters))
set.seed(1234)
fct_encode_one_hot(factor(sample(letters[1:4], 10, TRUE)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.