mm <- Matrix(toeplitz(c(10, 0, 1, 0, 3)), sparse = TRUE)
mm # automatically dsCMatrix
str(mm)
## how would we go from a manually constructed Tsparse* :
mT <- as(mm, "dgTMatrix")
## Either
(symM <- as(mT, "symmetricMatrix"))# dsT
(symC <- as(symM, "CsparseMatrix"))# dsC
## or
sC <- Matrix(mT, sparse=TRUE, forceCheck=TRUE)
sym2 <- as(symC, "TsparseMatrix")
## --> the same as 'symM', a "dsTMatrix"
stopifnot(identical(symC, sC), identical(sym2, symM),
class(sym2) == "dsTMatrix",
identical(sym2[1,], sC[1,]),
identical(sym2[,2], sC[,2]))
Run the code above in your browser using DataLab