fct_inorder: Reorder factor levels by first appearance, frequency, or...

View source: R/reorder.R

fct_inorderR Documentation

Reorder factor levels by first appearance, frequency, or numeric order

Description

This family of functions changes only the order of the levels.

  • fct_inorder(): by the order in which they first appear.

  • fct_infreq(): by number of observations with each level (largest first)

  • fct_inseq(): by numeric value of level.

Usage

fct_inorder(f, ordered = NA)

fct_infreq(f, w = NULL, 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.

w

An optional numeric vector giving weights for frequency of each value (not level) in f.

Examples

f <- factor(c("b", "b", "a", "c", "c", "c"))
f
fct_inorder(f)
fct_infreq(f)

f <- factor(1:3, levels = c("3", "2", "1"))
f
fct_inseq(f)

forcats documentation built on Feb. 16, 2023, 8:57 p.m.