as_factor | R Documentation |
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 class 'factor'
as_factor(x, ...)
## S3 method for class 'character'
as_factor(x, ...)
## S3 method for class 'numeric'
as_factor(x, ...)
## S3 method for class 'logical'
as_factor(x, ...)
x |
Object to coerce to a factor. |
... |
Other arguments passed down to method. |
This is a generic function.
# Character object
x <- c("a", "z", "g")
as_factor(x)
as.factor(x)
# Character object containing numbers
y <- c("1.1", "11", "2.2", "22")
as_factor(y)
as.factor(y)
# Numeric object
z <- as.numeric(y)
as_factor(z)
as.factor(z)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.