Learn R Programming

taRifx (version 1.0.6.2)

sort.data.frame: Sort a data.frame

Description

Sorts a data frame by one or more variables

Usage

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

Arguments

x

Data.frame to sort

formula

Formula by which to sort the data.frame (e.g. ~group1+group2 sorts first by group1 then by group2)

decreasing

Ignored. Exists for compatibility with generic S3 method.

Used to pass ,drop=FALSE to [

Value

Returns a sorted data.frame

See Also

arrange

Examples

Run this code
# NOT RUN {
library(datasets)
sort.data.frame(ChickWeight,formula=~weight+Time)

mydf <- data.frame(col1 = runif(10))
rownames(mydf) <- paste("x", 1:10, sep = "")
sort(mydf, f = ~col1) # drops a dimension
sort(mydf, f = ~col1, drop = FALSE) # does not drop a dimension (returns a data.frame)
# }

Run the code above in your browser using DataLab