Skip to contents
  • permute() rearranges a data matrix according to a permutation order.

  • get_order() returns the seriation order for rows and/or columns.

Usage

permute(object, order, ...)

get_order(x, ...)

# S4 method for data.frame,PermutationOrder
permute(object, order)

# S4 method for matrix,PermutationOrder
permute(object, order)

# S4 method for PermutationOrder
get_order(x, margin = c(1, 2))

Arguments

object

A \(m \times p\) numeric matrix or data.frame of count data (absolute frequencies giving the number of individuals for each category, i.e. a contingency table). A data.frame will be coerced to a numeric matrix via data.matrix().

...

Currently not used.

x, order

A PermutationOrder object giving the permutation order for rows and columns.

margin

A numeric vector giving the subscripts which the rearrangement will be applied over: 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns.

Value

  • permute() returns a permuted matrix or a permuted data.frame (the same as object).

See also

Author

N. Frerebeau

Examples

## Replicates Desachy 2004 results
data("compiegne", package = "folio")

## Get seriation order for columns on EPPM using the reciprocal averaging method
## Expected column order: N, A, C, K, P, L, B, E, I, M, D, G, O, J, F, H
(indices <- seriate_rank(compiegne, EPPM = TRUE, margin = 2))
#> <RankPermutationOrder>
#> Permutation order for matrix seriation:
#> - Row order: 1 2 3 4 5...
#> - Column order: 14 1 3 11 16 12 2 5 9 13 4 7 15 10 6 8...

## Get permutation order
get_order(indices, 1) # rows
#> [1] 1 2 3 4 5
get_order(indices, 2) # columns
#>  [1] 14  1  3 11 16 12  2  5  9 13  4  7 15 10  6  8

## Permute columns
(new <- permute(compiegne, indices))
#>      N     A     C    K   P    L    B    E   I   M    D    G   O    J    F    H
#> 5 1510 13740  8270 1740   0  460  375   20   0   0  250   40 350    5   10   80
#> 4  565 13540 10110 7210 450 1785 1520 1230   0 410  740  265 310  105  635  400
#> 3  160 12490  4220 6750 275 5930 5255 1395  30 350  980  440  10  580 1415  680
#> 2  410  6940  5800 2130 410 2410 2880 1510 620 910 3400 1080 310 2075 2280 2840
#> 1  190  6490  6900 1080  50  570 2350  670 340 740 2745  950 985 2660 3020 6700

## See the vignette
if (FALSE) {
utils::vignette("seriation")
}