sort.data.frame: Sort Data Frame

View source: R/sort.data.frame.R

sort.data.frameR Documentation

Sort Data Frame

Description

Sort data frame by one or more columns.

Usage

## S3 method for class 'data.frame'
sort(x, decreasing = FALSE, by = seq_along(x),
  na.last = TRUE, ...)

Arguments

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 NA values are treated as being last in the sorting order.

...

ignored (S3 template).

Value

Data frame containing sorted data.

Note

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)),].


arnima-github/arni documentation built on Oct. 28, 2023, 6:18 p.m.