powered by
Converts a vector to a factor() and ensures that levels are in the order of the provided levels.
factor()
as_factor(x, levels, ordered = is.ordered(x))
(factor()).
(atomic vector()) Vector to convert to factor.
vector()
(character()) Levels of the new factor.
character()
(logical(1)) If TRUE, create an ordered factor.
logical(1)
TRUE
x = factor(c("a", "b")) y = factor(c("a", "b"), levels = c("b", "a")) # x with the level order of y as_factor(x, levels(y)) # y with the level order of x as_factor(y, levels(x))
Run the code above in your browser using DataLab