Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_factor

Convert to Factor


Description

Converts a vector to a factor() and ensures that levels are in the order of the provided levels.

Usage

as_factor(x, levels, ordered = is.ordered(x))

Arguments

x

(atomic vector())
Vector to convert to factor.

levels

(character())
Levels of the new factor.

ordered

(logical(1))
If TRUE, create an ordered factor.

Value

(factor()).

Examples

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))

mlr3misc

Helper Functions for 'mlr3'

v0.10.0
LGPL-3
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Patrick Schratz [aut] (<https://orcid.org/0000-0003-0748-6624>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.