Let's say I have a matrix with all 0's with the exception of the diagonal.
m <- matrix(ncol=3,nrow=3)
m[,1] <- c(1,0,0)
m[,2] <- c(0,1,0)
m[,3] <- c(0,0,1)
What logical check could I use to test if the upper and lower triangle of the matrix are zero?
all(m[lower.tri(m)] == 0, m[upper.tri(m)] == 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With