Reorder factors levels by first appearance or frequency

fct_inorder(f, ordered = NA)

fct_infreq(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