Compared to base R, when x is a character, this function creates
levels in the order in which they appear, which will be the same on every
platform. (Base R sorts in the current locale which can vary from place
to place.) When x is numeric, the ordering is based on the numeric
value and consistent with base R.
as_factor(x, ...) # S3 method for factor as_factor(x, ...) # S3 method for character as_factor(x, ...) # S3 method for numeric as_factor(x, ...) # S3 method for logical as_factor(x, ...)
| x | Object to coerce to a factor. |
|---|---|
| ... | Other arguments passed down to method. |
This is a generic function.
#> [1] a z g #> Levels: a z gas.factor(x)#> [1] a z g #> Levels: a g z#> [1] 1.1 11 2.2 22 #> Levels: 1.1 11 2.2 22as.factor(y)#> [1] 1.1 11 2.2 22 #> Levels: 1.1 11 2.2 22#> [1] 1.1 11 2.2 22 #> Levels: 1.1 2.2 11 22as.factor(z)#> [1] 1.1 11 2.2 22 #> Levels: 1.1 2.2 11 22