Examples for 'Matrix::dsCMatrix-class'


Numeric Symmetric Sparse (column compressed) Matrices

Aliases: dsCMatrix-class dsTMatrix-class Arith,dsCMatrix,dsCMatrix-method coerce,dsCMatrix,RsparseMatrix-method coerce,dsCMatrix,dgCMatrix-method coerce,dsCMatrix,dgTMatrix-method coerce,dsCMatrix,dgeMatrix-method coerce,dsCMatrix,dsRMatrix-method coerce,dsCMatrix,dsTMatrix-method coerce,dsCMatrix,dspMatrix-method coerce,dsCMatrix,dsyMatrix-method coerce,dsCMatrix,dtCMatrix-method coerce,dsCMatrix,lsCMatrix-method coerce,dsCMatrix,nsCMatrix-method coerce,matrix,dsCMatrix-method determinant,dsCMatrix,logical-method coerce,dsTMatrix,dgCMatrix-method coerce,dsTMatrix,dgTMatrix-method coerce,dsTMatrix,dgeMatrix-method coerce,dsTMatrix,dsRMatrix-method coerce,dsTMatrix,dsCMatrix-method coerce,dsTMatrix,dspMatrix-method coerce,dsTMatrix,dsyMatrix-method coerce,dsTMatrix,dtTMatrix-method coerce,dsTMatrix,lsTMatrix-method coerce,dsTMatrix,nsTMatrix-method coerce,matrix,dsTMatrix-method determinant,dsTMatrix,logical-method

Keywords: classes algebra

### ** Examples

mm <- Matrix(toeplitz(c(10, 0, 1, 0, 3)), sparse = TRUE)
mm # automatically dsCMatrix
5 x 5 sparse Matrix of class "dsCMatrix"
                   
[1,] 10  .  1  .  3
[2,]  . 10  .  1  .
[3,]  1  . 10  .  1
[4,]  .  1  . 10  .
[5,]  3  .  1  . 10
str(mm)
Formal class 'dsCMatrix' [package "Matrix"] with 7 slots
  ..@ i       : int [1:9] 0 1 0 2 1 3 0 2 4
  ..@ p       : int [1:6] 0 1 2 4 6 9
  ..@ Dim     : int [1:2] 5 5
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num [1:9] 10 10 1 10 1 10 3 1 10
  ..@ uplo    : chr "U"
  ..@ factors : list()
mT <- as(as(mm, "generalMatrix"), "TsparseMatrix")

## Either
(symM <- as(mT, "symmetricMatrix")) # dsT
5 x 5 sparse Matrix of class "dsTMatrix"
                   
[1,] 10  .  1  .  3
[2,]  . 10  .  1  .
[3,]  1  . 10  .  1
[4,]  .  1  . 10  .
[5,]  3  .  1  . 10
(symC <- as(symM, "CsparseMatrix")) # dsC
5 x 5 sparse Matrix of class "dsCMatrix"
                   
[1,] 10  .  1  .  3
[2,]  . 10  .  1  .
[3,]  1  . 10  .  1
[4,]  .  1  . 10  .
[5,]  3  .  1  . 10
## or
sT <- Matrix(mT, sparse=TRUE, forceCheck=TRUE) # dsT

sym2 <- as(symC, "TsparseMatrix")
## --> the same as 'symM', a "dsTMatrix"
## Don't show: 
stopifnot(identical(sT, symM), identical(sym2, symM),
          class(sym2) == "dsTMatrix",
          identical(sym2[1,], sT[1,]),
          identical(sym2[,2], sT[,2]))
## End(Don't show)

[Package Matrix version 1.5-3 Index]