Learn R Programming

sparsevctrs (version 0.3.3)

sparse-arithmatic: Vector arithmatic with sparse vectors

Description

Do arithmatic operations on sparse vectors while trying to void destroying the sparsity.

Usage

sparse_multiplication(x, y)

Value

A sparse vector of same type.

Arguments

x

A numeric vector.

y

A numeric vector.

Details

Note that this function works with both sparse and dense vectors for both x and y, returning a sparse or dense vector according to the input.

For sparse_multiplication() the class of the resulting vector depends on the classes of x and y. If both x and y are integer vectors then an integer vector is returned, otherwise a double vector is returned.

sparse_multiplication() will return a non-sparse vector if both x and y is non-sparse. Otherwise a sparse vector is returned.

sparse_multiplication() will destroy sparsity of sparse vectors with non-0 default values.

Examples

Run this code
x_sparse <- sparse_double(c(pi, 5, 0.1), c(2, 5, 10), 10)

sparse_multiplication(x_sparse, x_sparse)

Run the code above in your browser using DataLab