Learn R Programming

SparseM (version 0.38)

SparseM.ops: Basic Linear Algebra for Sparse Matrices

Description

Basic linear algebra operations for sparse matrices of class matrix.csr.

Arguments

x
matrix of class matrix.csr.
y
matrix of class matrix.csr or a dense matrix or vector.
value
replacement values.
i,j
vectors of elements to extract or replace.
nrow
optional number of rows for the result.
lag
an integer indicating which lag to use.
differences
an integer indicating the order of the difference.

Details

Linear algebra operations for matrices of class matrix.csr are designed to behave exactly as for regular matrices. In particular, matrix multiplication, kronecker product, addition, subtraction and various logical operations should work as with the conventional dense form of matrix storage, as does indexing, rbind, cbind, and diagonal assignment and extraction. The method diag may be used to extract the diagonal of a matrix.csr object, to create a sparse diagonal see SparseM.ontology.

References

Koenker, R and Ng, P. (2002). SparseM: A Sparse Matrix Package for R, http://www.econ.uiuc.edu/~roger/research

See Also

slm for sparse linear model fitting. SparseM.ontology for coercion and other class relations involving the sparse matrix classes.

Examples

Run this code
n1 <- 10
n2 <- 10
p <- 6
y <- rnorm(n1)
a <- rnorm(n1*p)
a[abs(a)<0.5] <- 0
A <- matrix(a,n1,p)
A.csr <- as.matrix.csr(A)
b <- rnorm(n2*p)
b[abs(b)<1.0] <- 0
B <- matrix(b,n2,p)
B.csr <- as.matrix.csr(B)

# matrix transposition and multiplication
A.csr%*%t(B.csr)

# kronecker product
A.csr %x% matrix(1:4,2,2)

Run the code above in your browser using DataLab