SparseArray-Ops-methods | R Documentation |
SparseArray derivatives support operations from the Arith
,
Compare
, and Logic
groups, with some restrictions.
All together, these groups are referred to as the Ops
group.
See ?S4groupGeneric
in the methods package
for more information about the Ops
group generic.
IMPORTANT NOTES:
Only SVT_SparseArray objects are supported at the moment. Support for COO_SparseArray objects might be added in the future.
Arith
operations don't support SVT_SparseArray
objects of type()
"complex"
at the moment.
Two forms of operations are supported:
Between an SVT_SparseArray object svt
and a single
value y
:
svt op y y op svt
The operations from the Arith
group that support this form
are: *
, /
, ^
, %%
,%/%
.
Note that, except for *
(for which both svt * y
and y * svt
are supported), single value y
must
be on the right e.g. svt ^ 3
.
All operations from the Compare
group support this form,
with single value y
either on the left or the right.
However, there are some operation-dependent restrictions on the
value of y
.
Between two SVT_SparseArray objects svt1
and
svt2
of same dimensions (a.k.a. conformable arrays):
svt1 op svt2
The operations from the Arith
group that support this form
are: +
, -
, *
.
The operations from the Compare
group that support this form
are: !=
, <
, >
.
A SparseArray derivative of the same dimensions as the input object(s).
S4groupGeneric
in the methods package.
SparseArray objects.
Ordinary array objects in base R.
m <- matrix(0L, nrow=15, ncol=6)
m[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <- 101:126
svt <- SparseArray(m)
## Can be 5x or 10x faster than with a dgCMatrix object on a big
## SVT_SparseMatrix object!
svt2 <- (svt^1.5 + svt)
svt2
## Sanity check:
m2 <- (m^1.5 + m)
stopifnot(identical(as.matrix(svt2), m2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.