emptySparse {MatrixExtra}R Documentation

Create Empty Sparse Matrix

Description

Creates an empty sparse matrix (all values being zeros) with the requested format and dimensions. This is a faster alternative to calling 'Matrix::Matrix(0, ...)'.

Usage

emptySparse(nrow = 0L, ncol = 0L, format = "R", dtype = "d")

Arguments

nrow

Desired number of rows for the matrix.

ncol

Desired number of columns for the matrix.

format

Storage format for the matrix. Options are:

  • "R", which will output a CSR Matrix ("RsparseMatrix").

  • "C", which will output a CSC Matrix ("CsparseMatrix").

  • "T", which will output a COO/triplets Matrix ("TsparseMatrix").

dtype

Data type for the matrix. Options are:

  • "d", which will output a numeric/double type (e.g. "dgRMatrix").

  • "l", which will output a logical/boolean type.

  • "n", which will output a binary type.

Value

A sparse matrix of general type, with the specific class determined by 'format' and 'dtype'.

Examples

### This is very fast despite the large dimensions,
### as no data is held in the resulting object
library(MatrixExtra)
X <- emptySparse(nrow=2^20, ncol=2^25, format="T")

[Package MatrixExtra version 0.1.15 Index]