In contrast to the default behaviour of as.factor
, this
function uses the unsorted unique values of x
as levels and not sorted
unique values.
toFactor(x)
x | vector to be converted to factor |
---|
x <- c("b", "c", "a") as.factor(x) # Levels: a b c#> [1] b c a #> Levels: a b ctoFactor(x) # Levels: b c a#> [1] b c a #> Levels: b c a