as_matrix: Convert sparse matrix into dense matrix

View source: R/as_matrix.R

as_matrixR Documentation

Convert sparse matrix into dense matrix

Description

Convert sparse matrix into dense matrix

Usage

as_matrix(x, parallel = FALSE, sparse = FALSE)

Arguments

x

A matrix.

parallel

Logical value, default is FALSE. Setting to parallelize the computation with RcppParallel::setThreadOptions.

sparse

Logical value, default is FALSE, whether to output a sparse matrix.

Value

A dense or sparse matrix

Examples

m <- simulate_sparse_matrix(
  1000, 1000,
  decimal = 3
)

system.time(
  a <- as.matrix(m)
)
system.time(
  b <- as_matrix(m)
)
system.time(
  c <- as_matrix(m, parallel = TRUE)
)
system.time(
  d <- as_matrix(m, sparse = TRUE)
)

m[1:5, 1:5]
a[1:5, 1:5]
b[1:5, 1:5]
c[1:5, 1:5]

identical(a, b)
identical(a, c)
identical(b, c)
identical(a, d)
identical(b, d)

thisutils documentation built on July 3, 2025, 9:09 a.m.