reorder_mat: Reorder the rows and columns of a symmetric matrix

View source: R/reorder_mat.R

reorder_matR Documentation

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)

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.

Details

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

Value

A reordered symmetric matrix

Author(s)

P. Savary

Examples

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)

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.