grouping
Grouping Permutation

Description

Gives ordering of elements of a set of variables, so equivalent values are contiguous.

Usage

grouping(...)

Arguments

... Any number of objects, all of which have the same length.

Details

The permutation vector is essentially that given by order(...)). However, each character argument, arg_i, is first replaced by match(arg_i, unique(arg_i)). Also, note that if any argument arg_i has a class attribute, then it is replaced by xtfrm(arg_i), just as is done in the order function.
Value
returns the permutation vector, which is given the class "grouping." Also returns the following two attributes, which are computed from the input vectors (perhaps processed by xtfrm).
See Also
order, xtfrm
Examples
grouping(c(4,5,6,4,5,5), rep(c("Old","New"),c(4,2)))
d <- data.frame(Value=c(4,5,6,4,5,5), Which=rep(c("Old","New"),c(4,2)),
    stringsAsFactors=FALSE)
p <- do.call(grouping, d)
dp <- d[p,]
dp$group <- rep(seq_along(attr(p, "ends")), diff(c(0,attr(p,"ends"))))
dp
Package base version 6.1.1-7
Package Index