coerce_to_sparse_matrix {sparsevctrs}R Documentation

Coerce sparse data frame to sparse matrix

Description

Turning data frame with sparse columns into sparse matrix using Matrix::sparseMatrix().

Usage

coerce_to_sparse_matrix(x)

Arguments

x

a data frame or tibble with sparse columns.

Details

No checking is currently do to x to determine whether it contains sparse columns or not. Thus it works with any data frame. Needless to say, creating a sparse matrix out of a dense data frame is not ideal.

Value

sparse matrix

See Also

coerce_to_sparse_data_frame() coerce_to_sparse_tibble()

Examples


sparse_tbl <- lapply(1:10, function(x) sparse_double(x, x, length = 10))
names(sparse_tbl) <- letters[1:10]
sparse_tbl <- as.data.frame(sparse_tbl)
sparse_tbl

res <- coerce_to_sparse_matrix(sparse_tbl)
res


[Package sparsevctrs version 0.1.0 Index]