Learn R Programming

graph4lg (version 1.8.0)

reorder_mat: Reorder the rows and columns of a symmetric matrix

Description

The function reorders the rows and columns of a symmetric matrix according to a specified order.

Usage

reorder_mat(mat, order)

Value

A reordered symmetric matrix

Arguments

mat

An object of class matrix

order

A character vector with the rows and columns names of the matrix in the order in which they will be ordered by the function. All its elements must be rows and columns names of the matrix mat.

Author

P. Savary

Details

The matrix mat must be symmetric and have rows and columns names. Its values are not modified.

Examples

Run this code
mat <- matrix(rnorm(36), 6)
mat[lower.tri(mat)] <- t(mat)[lower.tri(mat)]
row.names(mat) <- colnames(mat) <- c("A", "C", "E", "B", "D", "F")
order <- c("A", "B", "C", "D", "E", "F")
mat <- reorder_mat(mat = mat, order = order)

Run the code above in your browser using DataLab