# as_factor

From mlr3misc v0.1.0
by Michel Lang

##### Convert to Factor

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

```
# NOT RUN {
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))
# }
```

*Documentation reproduced from package mlr3misc, version 0.1.0, License: LGPL-3*

### Community examples

Looks like there are no examples yet.