In R, is there a way to tell if a matrix is sparse? There are many sparse matrix classes, for example dgCMatrix, and there is no is.sparseMatrix method.
You could use the "spam" package: as.spam(..) makes an object of class spam out of your matrix and then apply summary(..), witch gives you the density of your matrix or display(..), for a graphical representation of the non-zero entries
testMatrix <-as.spam(matrix(c(123, 2, 0, 0, 0, 2, 23, 0, 0), nrow = 3))
summary(testMatrix)
display(testMatrix)
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