View source: R/fix_functions.R
fix_factors | 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,
select = 1:ncol(x),
drop = TRUE,
make.nice = FALSE,
tolower = FALSE,
track = TRUE
)
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 |
drop |
Drop similar levels? |
make.nice |
Remove problematic characters |
tolower |
Change all upper case characters to lower case |
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.