library(utils, pos = "package:base", verbose = FALSE)
mm <- Matrix(toeplitz(c(10, 0, 1, 0, 3)), sparse = TRUE)
mm # automatically dsCMatrix
str(mm)
mT <- as(as(mm, "generalMatrix"), "TsparseMatrix")
## Either
(symM <- as(mT, "symmetricMatrix")) # dsT
(symC <- as(symM, "CsparseMatrix")) # dsC
## or
sT <- Matrix(mT, sparse=TRUE, forceCheck=TRUE) # dsT
sym2 <- as(symC, "TsparseMatrix")
## --> the same as 'symM', a "dsTMatrix"
# \dontshow{
stopifnot(identical(sT, symM), identical(sym2, symM),
class(sym2) == "dsTMatrix",
identical(sym2[1,], sT[1,]),
identical(sym2[,2], sT[,2]))
# }
Run the code above in your browser using DataLab