fix_factors {clickR} | R Documentation |
Fixes factors imported as numerics. It is usual in some fields to encode
factor variables as integers. This function detects such variables and transforms
them into factors. When drop=TRUE
(by default) it detects multiple versions
of the same levels due to different capitalization, whitespaces or non-ASCII characters.
fix_factors(x, k = 5, drop = TRUE, track = TRUE)
x |
A data.frame |
k |
Maximum number of different numeric values to be converted to factor |
drop |
Drop similar levels? |
track |
Keep track of changes? |
# mtcars data has all variables encoded as numeric, even the factor variables.
descriptive(mtcars)
# After using fix_factors, factor variables are recognized as such.
descriptive(fix_factors(mtcars))