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.
A data frame with encoded variables. For one-hot encoding, original categorical columns are replaced by binary columns.
Arguments
data
A data frame containing categorical variables.
cols
The column indices or names of selected categorical variables. If NULL (default), all factor and character columns are selected automatically. An error is raised if any explicitly selected column is not categorical.
method
Encoding method. One of "label" (integer labels), "frequency" (frequency of each category), or "onehot" (binary indicator columns).
group
Optional grouping column for grouped frequency encoding.
prefix
Prefix for one-hot encoded column names (used only when method = "onehot").