Learn R Programming

ribiosUtils (version 1.5-6)

sortByCol: Sort data.frame rows by values in specified columns

Description

Sort rows of an data.frame by values in specified columns.

Usage

sortByCol(
  data.frame,
  columns,
  na.last = TRUE,
  decreasing = TRUE,
  orderAsAttr = FALSE
)

Arguments

data.frame

A data.frame object

columns

Column name(s) which sould be ordered

na.last

Logical, whether NA should be sorted as last

decreasing

Logical, whether the sorting should be in the decreasing order

orderAsAttr

Logical, whether the order index vectors should be returned in the attribute “order” of the sorted data.frame

Value

Sorted data.frame

Details

Columns can be specified by integer indices, logical vectors or character names.

Examples

Run this code
# NOT RUN {
sample.df <- data.frame(teams=c("HSV", "BVB", "FCB", "FCN"),pts=c(18,17,17,9), number=c(7,7,6,6))
sortByCol(sample.df, 1L)
sortByCol(sample.df, 1L, decreasing=FALSE)

sortByCol(sample.df, c(3L, 1L))
sortByCol(sample.df, c(3L, 1L), decreasing=FALSE)
sortByCol(sample.df, c(3L, 2L))

sortByCol(sample.df, c(TRUE, FALSE, TRUE))

sortByCol(sample.df, c("teams", "pts"))
sortByCol(sample.df, c("pts", "number", "teams"))
sortByCol(sample.df, c("pts", "teams", "number"))

# }

Run the code above in your browser using DataLab