matrixStats icon indicating copy to clipboard operation
matrixStats copied to clipboard

IDEA: Allow to use `dim.` argument that use a subset of the input object?

Open HenrikBengtsson opened this issue 6 years ago • 1 comments

Adding this here mostly as a note to self, but it might be of interest to others as well:

Currently it is asserted that prod(dim.) == length(x). For example:

> x <- array(1:24, dim=c(2, 3, 4))
> matrixStats::colMeans2(x, dim. = c(2, 3))
Error in matrixStats::colMeans2(x, dim. = c(2, 3)) : 
  Argument 'dim' does not match length of argument 'x': 2 * 3 != 24

Would it make sense to relax this to require prod(dim.) <= length(x)? Then one could do:

> matrixStats::colMeans2(x, dim. = c(2, 3))
[1] 1.5 3.5 5.5

in place of:

> matrixStats::colMeans2(x[, , 1], dim. = c(2, 3))

The idea is to also support something corresponding to:

> matrixStats::colMeans2(x[, , 2], dim. = c(2, 3))

which is more challenging because it would require also controlling the offset position.

HenrikBengtsson avatar Apr 12 '18 21:04 HenrikBengtsson

Maybe along those lines - how would I run colSds on the third dimension of a 3D array?

gvogler avatar May 31 '19 00:05 gvogler