SparseArray summarization methods
SparseArray-summarization.Rd
The SparseArray package provides memory-efficient summarization
methods for SparseArray objects. The following methods are
supported at the moment: anyNA()
, any()
, all()
,
min()
, max()
, range()
, sum()
, prod()
,
mean()
, var()
, sd()
.
More might be added in the future.
Note that these are S4 generic functions defined in base R and in the BiocGenerics package, with default methods defined in base R. This man page documents the methods defined for SparseArray objects.
Details
All these methods operate natively on the COO_SparseArray or SVT_SparseArray representation, for maximum efficiency.
Value
See man pages of the corresponding default methods in the
base package (e.g. ?base::range
,
?base::mean
, etc...) for the value returned
by these methods.
See also
SparseArray objects.
The man pages of the various default methods defined in the base package e.g.
base::range
,base::mean
,base::anyNA
, etc...
Examples
svt0 <- SVT_SparseArray(dim=c(4, 5, 2))
svt0[c(1:2, 8, 10, 15:17, 24:26, 28, 40)] <- (1:12)*10L
svt0[4, 3, 1] <- NA
svt0
#> <4 x 5 x 2 SparseArray> of type "integer" [nzcount=13 (32%)]:
#> ,,1
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 10 0 0 0 70
#> [2,] 20 0 40 0 0
#> [3,] 0 0 0 50 0
#> [4,] 0 30 NA 60 0
#>
#> ,,2
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 90 0 0 0
#> [2,] 0 100 0 0 0
#> [3,] 0 0 0 0 0
#> [4,] 80 110 0 0 120
#>
anyNA(svt0)
#> [1] TRUE
range(svt0)
#> [1] NA NA
range(svt0, na.rm=TRUE)
#> [1] 0 120
sum(svt0, na.rm=TRUE)
#> [1] 780
sd(svt0, na.rm=TRUE)
#> [1] 36.05551
## Sanity checks:
a0 <- as.array(svt0)
stopifnot(
identical(anyNA(svt0), anyNA(a0)),
identical(range(svt0), range(a0)),
identical(range(svt0, na.rm=TRUE), range(a0, na.rm=TRUE)),
identical(sum(svt0), sum(a0)),
identical(sum(svt0, na.rm=TRUE), sum(a0, na.rm=TRUE)),
all.equal(sd(svt0, na.rm=TRUE), sd(a0, na.rm=TRUE))
)