Learn R Programming

thisutils (version 0.3.1)

as_matrix: Convert matrix into dense/sparse matrix

Description

Convert matrix into dense/sparse matrix

Usage

as_matrix(x, return_sparse = FALSE)

Value

A dense or sparse matrix.

Arguments

x

A matrix.

return_sparse

Whether to output a sparse matrix. Default is FALSE.

Examples

Run this code
m <- simulate_sparse_matrix(
  1000, 1000,
  decimal = 3
)

a <- as_matrix(m)
a[1:5, 1:5]

b <- as_matrix(m, return_sparse = TRUE)
b[1:5, 1:5]

Run the code above in your browser using DataLab