Rollup (aggregate) sparse arrays along arbitrary dimensions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
rollup(x, MARGIN, INDEX, FUN, ...) ## S3 method for class 'simple_triplet_matrix' rollup(x, MARGIN, INDEX = NULL, FUN = sum, ..., REDUCE = FALSE) ## S3 method for class 'simple_sparse_array' rollup(x, MARGIN, INDEX = NULL, FUN = sum, ..., DROP = FALSE, EXPAND = c("none", "sparse", "dense", "all"), MODE = "double") ## S3 method for class 'matrix' rollup(x, MARGIN, INDEX = NULL, FUN = sum, ..., DROP = FALSE, MODE = "double") ## S3 method for class 'array' rollup(x, MARGIN, INDEX = NULL, FUN = sum, ..., DROP = FALSE, MODE = "double")
a sparse (or dense) array, typically of numeric or logical values.
a vector giving the subscripts (names) of the dimensions to be rolled up.
a corresponding (
the name of the function to be applied.
option to remove zeros from the result.
option to delete the dimensions of the result which have only one level.
the cell expansion method to use (see Details).
the type to use for the values if the result is empty.
optional arguments to
Provides aggregation of sparse and dense arrays, in particular fast summation over the rows or columns of sparse matrices in
If (a component of)
NA values the
corresponding parts of
x are omitted.
simple_sparse_array the following cell expansion methods are
The non-zero entries of a cell, if any, are
FUN as a
The number of zero entries of a cell is supplied in addition to above, as a second argument.
Cells with non-zero entries are expanded to
array and supplied to
All cells are expanded to a dense
and supplied to
Note that the memory and time consumption increases with the level of expansion.
Note that the default method tries to coerce
An object of the same class as
x where for class
simple_triplet_matrix the values are always of type
FUN = sum (default).
dimnames corresponding to
MARGIN are based on (the
Currently most of the code is written in R and, therefore, the memory and time it consumes is not optimal.
apply for dense arrays.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
## x <- matrix(c(1, 0, 0, 2, 1, NA), nrow = 2, dimnames = list(A = 1:2, B = 1:3)) x apply(x, 1L, sum, na.rm = TRUE) ## rollup(x, 2L, na.rm = TRUE) ## rollup(x, 2L, c(1,2,1), na.rm = TRUE) ## omit rollup(x, 2L, c(1,NA,1), na.rm = TRUE) ## expand a <- as.simple_sparse_array(x) a r <- rollup(a, 1L, FUN = mean, na.rm = TRUE, EXPAND = "dense") as.array(r) ## r <- rollup(a, 1L, FUN = function(x, nz) length(x) / (length(x) + nz), EXPAND = "sparse" ) as.array(r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.