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.
Usage
fix_factors(x, k = 5, select = 1:ncol(x), drop = TRUE, track = TRUE)
Arguments
x
A data.frame
k
Maximum number of different numeric values to be converted to factor
select
Numeric vector with the positions (all by default) to be affected by the function
# 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))