View source: R/encode_categorical.R
| encode_categorical | R Documentation |
Converts factor or character columns into numeric representations using label encoding, frequency encoding, or one-hot encoding. One-hot encoding creates binary indicator columns for each category.
encode_categorical(data, cols = NULL, method = "label",
group = NULL, prefix = "enc_", verbose = FALSE)
data |
A data frame containing categorical variables. |
cols |
The column indices or names of selected categorical variables. If |
method |
Encoding method. One of |
group |
Optional grouping column for grouped frequency encoding. |
prefix |
Prefix for one-hot encoded column names (used only when |
verbose |
Logical; if |
A data frame with encoded variables. For one-hot encoding, original categorical columns are replaced by binary columns.
# Label encoding
encode_categorical(data[1:100, c(1, 4)], cols = 2, method = "label")
# One-hot encoding
encode_categorical(data[1:100, c(1, 4)], cols = 2, method = "onehot")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.