sort.data.frame: Sort a data.frame

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Sorts a data frame by one or more variables

Usage

1
2
3
  ## S3 method for class 'data.frame'
 sort(x, decreasing = NULL, formula,
    ...)

Arguments

x

Data.frame to sort

formula

Formula by which to sort the data.frame (e.g. ~group1+group2 sorts first by group1 then by group2)

decreasing

Ignored. Exists for compatibility with generic S3 method.

...

Used to pass ,drop=FALSE to [

Value

Returns a sorted data.frame

Note

Modifications by Ari Friedman and Roman Lustrik Original Author: Kevin Wright http://tolstoy.newcastle.edu.au/R/help/04/09/4300.html Some ideas from Andy Liaw http://tolstoy.newcastle.edu.au/R/help/04/07/1076.html Use + for ascending, - for decending. Sorting is left to right in the formula

If you are Kevin Wright, please contact me. I have attempted to reach you by every means thinkable, to no avail. My assumption is that this is in the public domain since you posted it for others to use, but please tell me if that is not the case.

Author(s)

Kevin Wright, with generic compatibility by Ari B. Friedman

See Also

arrange

Examples

1
2
3
4
5
6
7
library(datasets)
sort.data.frame(ChickWeight,formula=~weight+Time)

mydf <- data.frame(col1 = runif(10))
rownames(mydf) <- paste("x", 1:10, sep = "")
sort(mydf, f = ~col1) # drops a dimension
sort(mydf, f = ~col1, drop = FALSE) # does not drop a dimension (returns a data.frame)

gsk3/taRifx documentation built on May 17, 2019, 8:55 a.m.