| rollup {slam} | R Documentation |
Rollup (aggregate) sparse arrays along arbitrary dimensions.
rollup(x, MARGIN, INDEX, FUN, ...) ## S3 method for class 'simple_triplet_matrix' rollup(x, MARGIN, INDEX, FUN = sum, ...) ## S3 method for class 'simple_sparse_array' rollup(x, MARGIN, INDEX, FUN = sum, ...) ## S3 method for class 'matrix' rollup(x, MARGIN, INDEX, FUN = sum, ...) ## S3 method for class 'array' rollup(x, MARGIN, INDEX, FUN = sum, ...)
x |
a sparse array containing numeric, integer, or logical values. |
MARGIN |
a vector giving the subscripts (names) of the dimensions to be rolled up. |
INDEX |
a corresponding ( |
FUN |
the name of the function to be applied. |
... |
optional arguments to |
Provides fast summation over the rows or columns of sparse matrices in
simple_triplet-form.
Note that the default method tries to coerce x to array.
An object of the same class as x where for class
simple_triplet_matrix the values are always of type double.
The dimnames are taken from (the components of) INDEX.
If (a component of) INDEX contains NA values the corresponding
positions are ignored.
Christian Buchta
simple_triplet_matrix and simple_sparse_array for sparse
arrays.
## x <- matrix(c(1, 0, 0, 2, 1, NA), nrow = 2, dimnames = list(A = 1:2, B = 1:3)) x zz <- rollup(x, 2L, c(1,2,1), na.rm = TRUE) zz ## s <- as.simple_triplet_matrix(x) z <- rollup(s, 2L, c(1,2,1), na.rm = TRUE) identical(zz, as.matrix(z)) ## a <- as.simple_sparse_array(s) z <- rollup(a, 2L, c(1,2,1), na.rm = TRUE) identical(as.array(zz), as.array(z)) ## zz <- rollup(x, 2L, c(1,NA,1), na.rm = TRUE) zz ## z <- rollup(s, 2L, c(1,NA,1), na.rm = TRUE) identical(zz, as.matrix(z)) ## z <- rollup(a, 2L, c(1,NA,1), na.rm = TRUE) identical(as.array(zz), as.array(z))