Learn R Programming

doBy (version 4.5-15)

orderBy: 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

orderBy(formula, data)

Arguments

formula
The right hand side of a formula
data
A data frame

Value

The ordered data frame

Details

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

See Also

summaryBy, transformBy, splitBy, lapplyBy,

Examples

Run this code
data(dietox)
orderBy(~Time+Evit, data=dietox)
## Sort decreasingly by Time
orderBy(~-Time+Evit, data=dietox)

Run the code above in your browser using DataLab