Examples for 'Matrix::formatSparseM'


Formatting Sparse Numeric Matrices Utilities

Aliases: formatSparseM .formatSparseSimple

Keywords: utilities print

### ** Examples

m <- suppressWarnings(matrix(c(0, 3.2, 0,0, 11,0,0,0,0,-7,0), 4,9))
fm <- formatSparseM(m)
noquote(fm)
                                    
[1,] .   11 .   3.2 . -7.0 .  .  .  
[2,] 3.2 .  -7 .    . .    .  .  .  
[3,] .   .  .  .    . .    11 .  3.2
[4,] .   .  .  11.0 .  3.2 .  -7 .  
## nice, but this is nicer {with "units" vertically aligned}:
print(fm, quote=FALSE, right=TRUE)
                                    
[1,] .   11  .  3.2 . -7.0  .  . .  
[2,] 3.2  . -7  .   .  .    .  . .  
[3,] .    .  .  .   .  .   11  . 3.2
[4,] .    .  . 11.0 .  3.2  . -7 .  
## and "the same" as :
Matrix(m)
4 x 9 sparse Matrix of class "dgCMatrix"
                                    
[1,] .   11  .  3.2 . -7.0  .  . .  
[2,] 3.2  . -7  .   .  .    .  . .  
[3,] .    .  .  .   .  .   11  . 3.2
[4,] .    .  . 11.0 .  3.2  . -7 .  
## align = "right" is cheaper -->  the "." are not aligned:
noquote(f2 <- formatSparseM(m,align="r"))
                                    
[1,] .   11 .   3.2 . -7.0 .  .  .  
[2,] 3.2 .  -7 .    . .    .  .  .  
[3,] .   .  .  .    . .    11 .  3.2
[4,] .   .  .  11.0 .  3.2 .  -7 .  
stopifnot(f2 == fm   |   m == 0, dim(f2) == dim(m),
         (f2 == ".") == (m == 0))

[Package Matrix version 1.5-3 Index]