rbind_csr {MatrixExtra} | R Documentation |
Concatenate two or more matrices and/or vectors by rows, giving a CSR matrix as result.
This is aimed at concatenating several CSR matrices or sparse vectors at a time, as it will be faster than calling 'rbind' which will only concatenate one at a time, resulting in unnecessary allocations.
rbind_csr(...)
... |
Inputs to concatenate. The function is aimed at CSR matrices ('dgRMatrix', 'ngRMatrix', 'lgRMatrix') and sparse vectors ('sparseVector'). It will work with other classes (such as 'dgCMatrix') but will not be as efficient. |
This function will not preserve the column names, if any were present.
A CSR matrix (class 'dgRMatrix', 'lgRMatrix', or 'ngRMatrix' depending on the inputs) with the inputs concatenated by rows.
library(Matrix)
library(MatrixExtra)
options("MatrixExtra.quick_show" = FALSE)
v <- as(1:10, "sparseVector")
rbind_csr(v, v, v)
X <- matrix(1:20, nrow=2)
rbind_csr(X, v)