Description Usage Arguments Details Value See Also Examples
Add indicators for all desired variables in a data set.
1 2 3 4 5 6 7 |
data |
A data frame |
var |
A character string/vector of names to be encoded. If NULL, the default, all character and factor variables will be encoded. |
nas |
What to do with missing values. For na.omit and na.exclude, any observations with missing data will be removed from the result. With na.pass, the default, the result will retain the missing values. Otherwise, with na.fail, an error will be thrown. |
sparse |
Logical (default FALSE). If true, will return only the encoded variables as a sparse matrix. |
keep.original |
Logical (default FALSE). Keep the original variables? Not an option if sparse is TRUE. |
This function is a simple one-hot encoder, with a couple options that are commonly desired. Takes the applicable variables and creates a binary indicator column for each unique value. If supplied non-factor/character variables, it will coerce them to characters and proceed accordingly. Will handle missingness, return a sparse matrix, or keep the original variable(s) as desired.
A data.frame with the encoded variables, or a sparse matrix of only the encoded variables.
1 2 3 4 5 6 7 8 9 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.