sort: Sorting Datasets

Description Usage Arguments Details Value See Also Examples

Description

Order the rows in a dataset.

Usage

1
2
3
4
## S3 method for class 'dataset'
sort(x, decreasing = FALSE, ...)
## S3 method for class 'dataset'
xtfrm(x)

Arguments

x

a dataset object.

decreasing

whether to sort in decreasing order.

...

ignored.

Details

The sort.dataset function converts its argument to a dataset and then sorts its rows. With decreasing = FALSE, the default, sorts rows in decreasing order; otherwise it sorts in increasing order.

The xtfrm.dataset function converts its argument to a dataset and then returns a numerical vector which is ordered in the same way as the rows of x.

In both cases, to determine the sort order, these functions first transform vector-like columns of x via xtfrm, and they transform matrix-like columns via xtfrm.dataset. Since xtfrm is not defined for list columns, both sort.dataset and xtfrm.dataset raise an error if x has a list column.

Value

For sort, a dataset with the rows of x ordered in ascending or descending order according to whether decreasing is FALSE.

For xtfrm, a numeric vector with entries in the same order as the rows of x.

See Also

reorder.

Examples

1
2
3
4
5
6
7
x <- dataset(a = c(5, 4, 3, 2, 1, 2, 3, 4, 5),
             b = c(2, 2, 1, 1, 2, 2, 1, 1, 2))
sort(x)
sort(x, decreasing = TRUE)

xt <- xtfrm(x)
x[order(xt), ]

patperry/r-frame documentation built on May 6, 2019, 8:34 p.m.