Reorder factors levels by first appearance, frequency, or numeric order.

fct_inorder(f, ordered = NA)

fct_infreq(f, ordered = NA)

fct_inseq(f, ordered = NA)

Arguments

f

A factor

ordered

A logical which determines the "ordered" status of the output factor. NA preserves the existing status of the factor.

Examples

f <- factor(c("b", "b", "a", "c", "c", "c")) f
#> [1] b b a c c c #> Levels: a b c
fct_inorder(f)
#> [1] b b a c c c #> Levels: b a c
fct_infreq(f)
#> [1] b b a c c c #> Levels: c b a
fct_inorder(f, ordered = TRUE)
#> [1] b b a c c c #> Levels: b < a < c
f <- factor(sample(1:10)) fct_inseq(f)
#> [1] 1 4 5 8 3 7 2 6 9 10 #> Levels: 1 2 3 4 5 6 7 8 9 10