Skip to contents

The function ofactor() is a convenience wrapper for factor() that orders the levels as they appear in the data if the levels argument is not specified.

Usage

ofactor(x = character(), ...)

Arguments

x

A vector of data, usually taking a small number of distinct values.

...

Other arguments passed on to base::factor().

Value

A factor. See base::factor() for details.

Examples

ofactor(3:1)
#> `ofactor()` is deprecated, use `forcats::fct_inorder()` instead.
#> [1] 3 2 1
#> Levels: 3 2 1
ofactor(9:12, exclude = 11)
#> [1] 9    10   <NA> 12  
#> Levels: 9 10 12
identical(ofactor(3:1, levels = 1:3), factor(3:1))
#> [1] TRUE