Learn R Programming

sparsevctrs (version 0.3.3)

coerce_to_sparse_tibble: Coerce sparse matrix to tibble with sparse columns

Description

Turning a sparse matrix into a tibble.

Usage

coerce_to_sparse_tibble(x, call = rlang::caller_env(0))

Value

tibble with sparse columns

Arguments

x

sparse matrix.

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

The only requirement from the sparse matrix is that it contains column names.

See Also

coerce_to_sparse_data_frame() coerce_to_sparse_matrix()

Examples

Run this code
set.seed(1234)
mat <- matrix(sample(0:1, 100, TRUE, c(0.9, 0.1)), nrow = 10)
colnames(mat) <- letters[1:10]
sparse_mat <- Matrix::Matrix(mat, sparse = TRUE)
sparse_mat

res <- coerce_to_sparse_tibble(sparse_mat)
res

# All columns are sparse
vapply(res, is_sparse_vector, logical(1))

Run the code above in your browser using DataLab