is.symmetric: Test for a symmetric matrix

View source: R/is.symmetric.R

is.symmetricR Documentation

Test for a symmetric matrix

Description

Test whether the supplied matrix is symmetric around diagonal

Usage

is.symmetric(m)

Arguments

m

a matrix to be tested

Details

I the matrix m is not a square matrix the function returns FALSE and issues a warning.

The testing boils down to comparing lower and upper triangles of the matrix m using the function identical.

Value

Logical, whether the matrix is symmetric or not.

See Also

See identical, matrix, upper.tri. Also symmetrize in package sna.

Examples

# create some matrix
m <- matrix( c(0, 1, 1, 0), ncol=2 )
m
is.symmetric(m) # TRUE

m1 <- m
m1[2,1] <- 0
m1
is.symmetric(m1) # FALSE

# supplying a non-square matrix
m2 <- matrix( 1:6, ncol=2 )
is.symmetric(m2) # FALSE with warning

# clean-up
rm(m, m1, m2)


mbojan/mbtools documentation built on Oct. 16, 2023, 8:18 p.m.