Learn R Programming

statnet.common (version 4.10.0)

order: Implement the sort and order methods for data.frame and matrix, sorting it in lexicographic order.

Description

These function return a data frame sorted in lexcographic order or a permutation that will rearrange it into lexicographic order: first by the first column, ties broken by the second, remaining ties by the third, etc..

Usage

order(..., na.last = TRUE, decreasing = FALSE)

# S3 method for default order(..., na.last = TRUE, decreasing = FALSE)

# S3 method for data.frame order(..., na.last = TRUE, decreasing = FALSE)

# S3 method for matrix order(..., na.last = TRUE, decreasing = FALSE)

# S3 method for data.frame sort(x, decreasing = FALSE, ...)

Value

For sort, a data frame, sorted lexicographically. For order, a permutation I (of a vector 1:nrow(x)) such that x[I,,drop=FALSE] equals x ordered lexicographically.

Arguments

...

Ignored for sort. For order, first argument is the data frame to be ordered. (This is needed for compatibility with order.)

na.last

See order documentation.

decreasing

Whether to sort in decreasing order.

x

A data.frame to sort.

See Also

Examples

Run this code

data(iris)

head(iris)

head(order(iris))

head(sort(iris))

stopifnot(identical(sort(iris),iris[order(iris),]))

Run the code above in your browser using DataLab