is.symmetric | R Documentation |
Test whether the supplied matrix is symmetric around diagonal
is.symmetric(m)
m |
a matrix to be tested |
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
.
Logical, whether the matrix is symmetric or not.
See identical
, matrix
,
upper.tri
. Also symmetrize
in package
sna.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.