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

Description Usage Arguments Details Value Author(s) Examples

Description

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

Usage

1
2
3
4
5
6
7
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

Details

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

Value

Sorted data.frame

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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"))

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.