| as_ordered | R Documentation |
As ordered
as_ordered(x)
## Default S3 method:
as_ordered(x)
x |
A vector of values |
Simple implementation of ordered. If x is ordered it is
simply returned. If x is a factor the ordered class is added.
Otherwise, x is made into a factor with fact() and then the
ordered class is added. Unlike just fact, ordered will replace the NA
levels with NA_integer_ to work appropriately with other functions.
An ordered vector
fact()
Other factors:
char2fact(),
drop_levels(),
fact(),
fact2char(),
fact_na()
x <- c("a", NA, "b")
x <- fact(x)
str(x) # NA is 3L
y <- x
class(y) <- c("ordered", class(y))
max(y)
max(y, na.rm = TRUE) # returns NA -- bad
# as_ordered() removes the NA level
x <- as_ordered(x)
str(x)
max(x, na.rm = TRUE) # returns b -- correct
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.