encode_ordinal {cleandata} | R Documentation |
Encode Ordinal Data Into Integers
Description
Encodes ordinal data into sequential integers by a given order. Optionally records the result into a log file.
Usage
encode_ordinal(x, order, none='', out.int=FALSE,
full_print=TRUE, log = eval.parent(in_log_default))
Arguments
x |
The data frame |
order |
a vector of the ordered labels from low to high. |
none |
The 'none'-but-not-'NA' level, which is always encoded to 0. |
out.int |
Whether to convert encoded |
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('y', 'z', 'x', 'y', 'z'))
B <- as.factor(c('y', 'x', 'z', 'z', 'x'))
C <- as.factor(c('k', 'i', 'i', 'j', 'k'))
df <- data.frame(A, B, C)
# encoding
df[, 1:2] <- encode_ordinal(df[,1:2], order = c('z', 'x', 'y'))
df[, 3] <- encode_ordinal(df[, 3, drop = FALSE], order = c('k', 'j', 'i'))
print(df)