sortDataframe: Sort data.frame according to multiple columns.

View source: R/sortDataframe.R

sortDataframeR Documentation

Sort data.frame according to multiple columns.

Description

Sort data.frame according to multiple columns.

Usage

sortDataframe(x, by = x, decreasing = FALSE, returnID = FALSE)

Arguments

x

a data.frame to sort.

by

either a data.frame, or a vector of characters, or a vector of integers. The data.frame x is sorted according to this parameter. If it is a data.frame, then the column names should be a part of column names of x. A vector of characters must not exceed the column names of x. The integer vector is the index of columns.

decreasing

logic. Should the sort order be increasing (default) or decreasing?

returnID

logic. If FALSE (default), the sorted index is not returned.

Value

A sorted data.frame according to 'by'.

Examples

## Not run: 
x = data.frame(a = c(3,3,6,4,4), b = c(4,2,2,1,1), c = 1:5)
sortDataframe(x)
sortDataframe(x, by = c("a", "b"))
sortDataframe(x, by = 1:2)
sortDataframe(x, by = x[, 1:2])
sortDataframe(x, returnID = TRUE)

## End(Not run)

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.