is.sorted: Check Whether Vectors are Sorted

View source: R/PCSmisc.R

is.sortedR Documentation

Check Whether Vectors are Sorted

Description

Check whether one or more vectors are sorted. In the case of more than one vector, the function checks if each vector is sorted within blocks of the preceeding vector(s).

Usage

is.sorted(...)

Arguments

...

One or more atomic vectors, all of the same length.

Details

If called with a single argument x, this function simply returns !is.unsorted(x). If called with more than one argument, then order is used on all arguments, and the result is compared to 1:n where n is the common length of all the arguments.

Thus, in the multiple vector case, the ordering is defined by the nested structure of the vectors (See example).

Value

A logical.

Author(s)

Benjamin Rich <mail@benjaminrich.net>

See Also

is.unsorted order

Examples

require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,]  # First 4 subjects
dat$id <- asID(dat$Subject)

attach(dat)

is.sorted(id)        # TRUE  - data are sorted by id
is.sorted(time)      # FALSE - data are NOT sorted by time
is.sorted(id, time)  # TRUE  - within id blocks, data are sorted by time

detach(dat)

benjaminrich/PCSmisc documentation built on Feb. 11, 2024, 9:25 p.m.