Computes ordered indices.
Similar to order,
except the user must supply a vector,
a list of equal-length vectors,
a data.frame or a matrix (row-wise and column-wise are both supported),
as the input.
For a vector x
, idx_ord_v(x)
is equivalent to
order(x)
.
For a data.frame or a list of equal-length vectors x
, with p
columns/elements, idx_ord_df(x)
is equivalent to order(x[[1]], ..., x[[p]])
.
For a matrix (or array) x
with p
rows, idx_ord_m(x, margin = 1)
is equivalent to order(x[1, ], ..., x[p, ], ...)
.
For a matrix (or array) x
with p
columns, idx_ord_m(x, margin = 2)
is equivalent to order(x[, 1], ..., x[, p], ...)
.
Note that these are merely convenience functions,
and that these are actually slightly slower than order
(except for idx_ord_v()
),
due to the additional functionality.
Arguments
Value
See order.
Examples
x <- sample(1:10)
order(x)
#> [1] 7 1 6 8 2 4 5 10 9 3
idx_ord_v(x)
#> [1] 7 1 6 8 2 4 5 10 9 3
idx_ord_m(rbind(x, x), 1)
#> [1] 7 1 6 8 2 4 5 10 9 3
idx_ord_m(cbind(x, x), 2)
#> [1] 7 1 6 8 2 4 5 10 9 3
idx_ord_df(data.frame(x, x))
#> [1] 7 1 6 8 2 4 5 10 9 3