| sparseVector {Matrix} | R Documentation |
User friendly construction sparse vectors,
i.e., objects inheriting from class
sparseVector, from indices and values of its
nonzero entries.
sparseVector(x, i, length)
x |
vector of the non zero entries. |
i |
integer vector (of the same length as |
length |
length of the sparse vector. |
zero entries in x are dropped automatically, analogously as
drop0() acts on sparse matrices.
a sparse vector, i.e., inheriting from class
sparseVector.
Martin Maechler
sparseMatrix() constructor for sparse matrices;
the class sparseVector.
str(sv <- sparseVector(x = 1:10, i = sample(999, 10), length=1000))
sx <- c(0,0,3, 3.2, 0,0,0,-3:1,0,0,2,0,0,5,0,0)
ss <- as(sx, "sparseVector")
stopifnot(identical(ss,
sparseVector(x = c(2, -1, -2, 3, 1, -3, 5, 3.2),
i = c(15L, 10:9, 3L,12L,8L,18L, 4L), length = 20L)))