encode_onehot {cleandata} | R Documentation |
One-Hot Encoding
Description
Encodes categorical data by One-hot encoding. Optionally records the result into a log file.
Usage
encode_onehot(x, colname.sep = '_', drop1st = FALSE,
full_print=TRUE, log = eval.parent(in_log_default))
Arguments
x |
The data frame |
colname.sep |
A character or string that acts as an divider in the names of the columns of encoding results. |
drop1st |
Whether drop the 1st level of every encoded column. The 1st level refers to the level that corresponds to 1 in a factor. |
full_print |
When set to |
log |
Controls log files. To produce log files, assign it or the |
Value
An encoded data frame.
Warning
x
can only be a data frame. Don't pass a vector to it.
See Also
Examples
# refer to vignettes if you want to use log files
message('refer to vignettes if you want to use log files')
# building a data frame
A <- as.factor(c('x', 'y', 'x'))
B <- as.factor(c('i', 'j', 'k'))
df <- data.frame(A, B)
# encoding
df0 <- encode_onehot(df)
df0 <- cbind(df, df0)
print(df0)
df0 <- encode_onehot(df, colname.sep = '-', drop1st = TRUE)
df0 <- cbind(df, df0)
rm(df)
print(df0)
[Package cleandata version 0.3.0 Index]