sort.data.frame: Sorts a dataframe by one or more variables

Description Usage Arguments Details Value Author(s) Examples

Description

Sorts a dataframe by one or more variables, ascending or descending The order of the arguments form and dat is interchangeable. In the formula, use + for ascending, - for decending. Sorting is left to right in the formula. For example, to sort the dataframe Oats with sorting variables Block and Variety, useage is either of the following:

Usage

1
2
sort.data.frame(form, dat)
sort.data.frame(dat, form)

Arguments

form

A formula with the variable names to use for sorting

dat

The dataframe to sort

Details

sort.data.frame(~ Block - Variety, Oats) or

sort.data.frame(Oats, ~ - Variety + Block)

Value

The sorted dataframe

Author(s)

Kevin Wright with ideas from Any Liaw and small edits by Landon Sego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
d <- data.frame(b=factor(c("Hi","Med","Hi","Low"),levels=c("Low","Med","Hi"),
                ordered=TRUE),
                x=c("A","D","A","C"),y=c(8,3,9,9),z=c(1,1,1,2))

# Sort by descending z, descending b
sort.data.frame(~-z-b,d)

# Sort by ascending x, ascending y, and ascending z
sort.data.frame(~x+y+z,d)

# Sort by descending x, ascending y, ascending z
sort.data.frame(~-x+y+z,d)

# Sort by ascending x, descending y, ascending z
sort.data.frame(d,~x-y+z)

PNNL-Comp-Mass-Spec/glmnetGLR documentation built on May 28, 2019, 2:23 p.m.