matrixStats
matrixStats copied to clipboard
IDEA: Allow to use `dim.` argument that use a subset of the input object?
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.
Maybe along those lines - how would I run colSds on the third dimension of a 3D array?