17 months ago by
United States
Hi,
No rowsum
method for DelayedMatrix objects yet, but there is a rowSums
method. In the meantime, here is a quick and dirty implementation for rowsum
that doesn't support reorder
or na.rm
(like rowsum.default
and rowsum.data.frame
do):
rowsum.DelayedMatrix <- function(x, group, reorder=TRUE, ...)
apply(x, 2, function(col) sum(splitAsList(col, group)))
Then:
library(DelayedArray)
M <- as(matrix(runif(100000), nrow=2000), "RleArray")
group <- sample(8, 2000, replace=TRUE)
identical(rowsum(M, group), rowsum(as.matrix(M), group))
# [1] TRUE
Is not as fast as on an ordinary matrix though...
Cheers,
H.
•
link
modified 17 months ago
•
written
17 months ago by
Hervé Pagès ♦♦ 13k