Description Usage Arguments Details Value Author(s) Examples
order
returns a permutation which rearranges its first
argument by value, and optionally by an additional grouping variable.
It is an extension of order
.
1 | ordergrouped(..., group, na.last = TRUE, decreasing = FALSE)
|
... |
|
group |
An optional factor variable for grouping. |
na.last |
See |
decreasing |
See |
Arguments are passed to order
. If group
is provided,
The permutations are then rearranged to respect the grouping.
An integer vector unless any of the inputs has 2^31 or more elements, when it is a double vector.
G. Sawitzki
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]
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.