Learn R Programming

sparsevctrs (version 0.3.3)

coerce_to_sparse_matrix: 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, call = rlang::caller_env(0))

Value

sparse matrix

Arguments

x

a data frame or tibble with sparse columns.

call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.

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.

See Also

coerce_to_sparse_data_frame() coerce_to_sparse_tibble()

Examples

Run this code
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

Run the code above in your browser using DataLab