order_by_summary: Order a factor by the summary statistic of another variable.

Description Usage Arguments Details Value Examples

View source: R/order_by.R

Description

The factor and the order must be of the same length. The order is summarised by the levels of factor, using the summary function. The outcome of summarising is used to order the factor variable.

Usage

1

Arguments

factor

A factor or character vector.

order

A numeric.

summary

A function to apply to each subset of order which will return a single number

desc

Set to TRUE to order descending.

...

Further arguments to summary

Details

Ties are arbitrarily ordered.

Value

An ordered factor

Examples

1
2
3
factor = letters[rep(c(1, 2), 2)]
order = 1:4
order_by_summary(factor, order)

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