ordergrouped: Ordering Permutation

Description Usage Arguments Details Value Author(s) Examples

Description

order returns a permutation which rearranges its first argument by value, and optionally by an additional grouping variable. It is an extension of order.

Usage

1
ordergrouped(..., group, na.last = TRUE, decreasing = FALSE)

Arguments

...
group

An optional factor variable for grouping.

na.last

See order.

decreasing

See order.

Details

Arguments are passed to order. If group is provided, The permutations are then rearranged to respect the grouping.

Value

An integer vector unless any of the inputs has 2^31 or more elements, when it is a double vector.

Author(s)

G. Sawitzki

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
x  <- c(1:3, 6:2)
names(x) <- c("n1gg1","n2g1","n3g2","n4g2","n5g2","n6g3","n7g3","n8g3")
gr <- c("g1","g1", "g2", "g2", "g2", "g3", "g3", "g3")

xperm <- ordergrouped(x, group=gr)
x[xperm]
gr[xperm]

## The function is currently defined as
function (..., group, na.last = TRUE, decreasing = FALSE) 
{
    if (missing(group)) {
        order(..., na.last = na.last, decreasing = decreasing)
    }
    else {
        ox <- order(..., na.last = na.last, decreasing = decreasing)
        ogro <- order(group[ox])
        ox[ogro]
    }
  }

bertin documentation built on May 2, 2019, 5:54 p.m.

Related to ordergrouped in bertin...