Learn R Programming

RCEIM (version 0.2)

sortDataFrame: Sorting a data frame by a key

Description

A simple function to sort a data frame based on a certain keyword. This function was posted by r-fanatic at http://snippets.dzone.com/posts/show/470.

Usage

sortDataFrame(x, key, ...)

Arguments

x
The data frame to be sorted.
key
The key by which the data frame will be sorted.
...
Further arguments to be passed to the order function.

Value

The sorted data frame.

References

http://snippets.dzone.com/posts/show/470.

Examples

Run this code
# Create a simple data frame and order using the "B" key
ppp <- data.frame(A=1:10,B=10:1)
ppp
sortDataFrame(ppp,"B")
ppp

Run the code above in your browser using DataLab