View source: R/sort.data.frame.R
sort.data.frame | R Documentation |
Sort data frame by one or more columns.
## S3 method for class 'data.frame'
sort(x, decreasing = FALSE, by = seq_along(x),
na.last = TRUE, ...)
x |
a data frame. |
decreasing |
whether to reverse the sorting order. |
by |
a vector containing column numbers or column names to sort by, negative means descending. |
na.last |
whether |
... |
ignored (S3 template). |
Data frame containing sorted data.
Based on an S News email from Xiangyang Liu, 7 Aug 1995.
As pointed out in the R-FAQ
, x[order(x$a,-x$b),]
can also be
used to sort by multiple columns. That approach, using the minus sign to
reverse the sort order, will not work for string variables unless they are
wrapped inside rank
: x[order(x$a,-rank(x$b)),]
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.