MeanDims fails when averaging all the dimensions
I have found a little bug in MeanDims()
function when trying to average all the dimensions of an array (it works perfect for the rest of the cases). This is an example:
> x <- array(1:40, dim = list(a = 2, b = 4, c = 6))
> MeanDims(data = x, dims = c('a','b','c'))
Error in dim(newX) <- c(prod(d.call), d2) :
dims [product 1] do not match the length of object [48]
A possible fix would be to change lines 81-84 for the following ones:
if (length(margins) == 0){
res <- mean(data, na.rm = na.rm)
} else {
res <- as.array(apply(data, margins, mean, na.rm = na.rm))
if (!is.null(names(dim(data))[margins]) & is.null(names(dim(res)))) {
names(dim(res)) <- names(dim(data))[margins]
}
}
Best regards,
Carlos