ohe | R Documentation |
One-hot encodes a single data.frame column or vector
ohe(var, drop_ref = TRUE)
var |
A vector or data.frame column of categorical variables |
drop_ref |
Logical, default = |
A data.frame of columns each representing a category in var
with binary indicators 0/1.
# Encode a vector
lets <- rep(letters[1:3], 3)
ohe(lets)
# Encode a single column of a data.frame
df <- data.frame(lets, x = runif(9))
ohe(df$lets)
# Encode just the categorical columns and combine
df2 <- data.frame(lets, LETS = rep(LETTERS[1:3], 3), x = rnorm(9))
data.frame(lapply(df2, function(x) if(is.factor(x)) { ohe(x) } else { x } ))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.