Learn R Programming

miscset (version 1.0.0)

sort: Sort data.frame Objects

Description

Sort a data.frame by any column(s).

Usage

"sort"(x, decreasing = FALSE, by = NULL, bye = NULL, na.last = NA, ...)

Arguments

x
A data.frame.
decreasing
Logical, sort in decreasing order. See also sort.
by
Index (integer) or names of columns in x to sort by in that order. If both by and bye are missing, all columns are used to sort in their order.
bye
Unquoted column name or list() or .() with unquoted column names to sort x by. Not evaluated if by is supplied.
na.last
TRUE to put missing values last, FALSE to put first or NA to remove.
...
Ignored for the data.frame method.

Examples

Run this code
#

d <- data.frame(a=c(1,1,1,2,NA),b=c(2,1,3,1,1),c=5:1)
d
sort(d) # sort by every column (a, then b, then c)
sort(d, TRUE, by="c") # decreasing by column 'c'
sort(d, bye=.(a,c)) # increasing by columns 'a' and then 'c'

#

Run the code above in your browser using DataLab