is.symmetric: Test for a symmetric matrix

Description Usage Arguments Details Value See Also Examples

View source: R/is.symmetric.R

Description

Test whether the supplied matrix is symmetric around diagonal

Usage

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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 Nov. 9, 2017, 3:21 p.m.