extractors {sparsevctrs} | R Documentation |
Information extraction from sparse vectors
Description
Extract positions, values, and default from sparse vectors without the need to materialize vector.
Usage
sparse_positions(x)
sparse_values(x)
sparse_default(x)
Arguments
x |
vector to be extracted from. |
Details
sparse_default()
returns NA
when applied to non-sparse vectors. This is
done to have an indicator of non-sparsity.
for ease of use, these functions also works on non-sparse variables.
Value
vectors of requested attributes
Examples
x_sparse <- sparse_double(c(pi, 5, 0.1), c(2, 5, 10), 10)
x_dense <- c(0, pi, 0, 0, 0.5, 0, 0, 0, 0, 0.1)
sparse_positions(x_sparse)
sparse_values(x_sparse)
sparse_default(x_sparse)
sparse_positions(x_dense)
sparse_values(x_dense)
sparse_default(x_dense)
x_sparse_3 <- sparse_double(c(pi, 5, 0.1), c(2, 5, 10), 10, default = 3)
sparse_default(x_sparse_3)
[Package sparsevctrs version 0.1.0 Index]