SparseM.ops {SparseM} | R Documentation |

## Basic Linear Algebra for Sparse Matrices

### Description

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

.

### Usage

### 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`

.

The function `det`

computes the determinant of the argument
matrix. If the matrix is of class `matrix.csr`

then it must
be symmetric, or an error will be returned. If the matrix is of
class `matrix.csr.chol`

then the determinant of the Cholesky
factor is returned, ie the product of the diagonal elements.

The function `norm`

is used to check for symmetry by
computing the maximum of the elements of the difference between
the matrix and its transpose. Optionally, this sup norm can
be replaced by the Hilbert-Schmidt norm, or the l1 norm.

### 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

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)

[Package

*SparseM* version 0.54

Index]