15
15
rollup(x, MARGIN, INDEX, FUN, ...)
17
\method{rollup}{simple_triplet_matrix}(x, MARGIN, INDEX, FUN, \dots)
18
\method{rollup}{simple_sparse_array}(x, MARGIN, INDEX, FUN, \dots)
19
\method{rollup}{matrix}(x, MARGIN, INDEX, FUN, \dots)
20
\method{rollup}{array}(x, MARGIN, INDEX, FUN, \dots)
17
\method{rollup}{simple_triplet_matrix}(x, MARGIN, INDEX, FUN = sum, \dots)
18
\method{rollup}{simple_sparse_array}(x, MARGIN, INDEX, FUN = sum, \dots)
19
\method{rollup}{matrix}(x, MARGIN, INDEX, FUN = sum, \dots)
20
\method{rollup}{array}(x, MARGIN, INDEX, FUN = sum, \dots)
23
23
\item{x}{a sparse array containing numeric, integer, or logical values.
25
\item{MARGIN}{a vector giving the subscripts of the dimensions to be rolled up.
25
\item{MARGIN}{a vector giving the subscripts (names) of the dimensions to be rolled up.
27
27
\item{INDEX}{a corresponding (\code{list} of) \code{factor} (components) in the sense that \code{as.factor(f)} defines the grouping.}
28
\item{FUN}{the function to be applied. Note that only functions that return a scalar value are applicable.
28
\item{FUN}{the name of the function to be applied.
30
30
\item{\dots}{optional arguments to \code{FUN}.
57
57
x <- matrix(c(1, 0, 0, 2, 1, NA), nrow = 2,
58
58
dimnames = list(A = 1:2, B = 1:3))
60
zz <- rollup(x, 2L, c(1,2,1), sum, na.rm = TRUE)
60
zz <- rollup(x, 2L, c(1,2,1), na.rm = TRUE)
63
63
s <- as.simple_triplet_matrix(x)
64
z <- rollup(s, 2L, c(1,2,1), sum, na.rm = TRUE)
64
z <- rollup(s, 2L, c(1,2,1), na.rm = TRUE)
65
65
identical(zz, as.matrix(z))
67
67
a <- as.simple_sparse_array(s)
68
z <- rollup(a, 2L, c(1,2,1), sum, na.rm = TRUE)
68
z <- rollup(a, 2L, c(1,2,1), na.rm = TRUE)
69
69
identical(as.array(zz), as.array(z))
71
zz <- rollup(x, 2L, c(1,NA,1), sum, na.rm = TRUE)
71
zz <- rollup(x, 2L, c(1,NA,1), na.rm = TRUE)
74
z <- rollup(s, 2L, c(1,NA,1), sum, na.rm = TRUE)
74
z <- rollup(s, 2L, c(1,NA,1), na.rm = TRUE)
75
75
identical(zz, as.matrix(z))
77
z <- rollup(a, 2L, c(1,NA,1), sum, na.rm = TRUE)
77
z <- rollup(a, 2L, c(1,NA,1), na.rm = TRUE)
78
78
identical(as.array(zz), as.array(z))