order_by_number: Order by the numbers in a factor.

Description Usage Arguments Details Value Examples

View source: R/order_by_content.R

Description

Order the factor by the numbers used in the factor. This function orders on symbolic numbers: 1, 2, 3 etc.

Usage

1

Arguments

factor

The factor you want to order

desc

Set to TRUE to order descending.

Details

Numbers present in the factor levels will be extracted and used to order the factor. If more than one continuous number is present in the factor level then the first number will be used for numbering.

Ties between two different factor levels are ordered arbitrarily.

Factor levels without numbers are ordered lowest arbitrarily.

Value

an ordered factor

Examples

1
2
3
4
5
f <- c('group_1', 'group_2', 'group_3')
order_by_number(f)

factor <- c('a_3', 'a_3', 'a_1', 'a', 'b')
order_by_number(factor)

mhairi/ordered documentation built on May 22, 2019, 8:57 p.m.