Learn R Programming

doBy (version 4.6.21)

by-order: Ordering (sorting) rows of a data frame

Description

Ordering (sorting) rows of a data frame by the certain variables in the data frame. This function is essentially a wrapper for the order() function - the important difference being that variables to order by can be given by a model formula.

Usage

order_by(data, formula)

orderBy(formula, data)

Value

The ordered data frame

Arguments

data

A dataframe

formula

The right hand side of a formula

Author

Søren Højsgaard, sorenh@math.aau.dk and Kevin Wright

Details

The sign of the terms in the formula determines whether sorting should be ascending or decreasing; see examples below

See Also

transformBy, transform_by, splitBy, split_by

Examples

Run this code

orderBy(~ conc + Treatment, CO2)
## Sort decreasingly by conc
orderBy(~ - conc + Treatment, CO2)

Run the code above in your browser using DataLab