Learn R Programming

Matrix (version 0.999375-42)

dgTMatrix-class: Sparse matrices in triplet form

Description

The "dgTMatrix" class is the class of sparse matrices stored as (possibly redundant) triplets. The internal representation is not at all unique, contrary to the one for class dgCMatrix.

Arguments

Objects from the Class

Objects can be created by calls of the form new("dgTMatrix", ...), but more typically via as(*, "dgTMatrix").

See Also

Class dgCMatrix or the superclasses dsparseMatrix and TsparseMatrix;

Examples

Run this code
m <- Matrix(0+1:28, nrow = 4)
m[-3,c(2,4:5,7)] <- m[ 3, 1:4] <- m[1:3, 6] <- 0
(mT <- as(m, "dgTMatrix"))
str(mT)
mT[1,]
mT[4, drop = FALSE]
stopifnot(identical(mT[lower.tri(mT)],
                    m [lower.tri(m) ]))
mT[lower.tri(mT,diag=TRUE)] <- 0
mT

Run the code above in your browser using DataLab