Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • s2dv s2dv
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 17
    • Issues 17
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Earth SciencesEarth Sciences
  • s2dvs2dv
  • Issues
  • #23
Closed
Open
Issue created Dec 16, 2020 by Carlos Delgado Torres@cdelgadoMaintainer

MeanDims fails when averaging all the dimensions

Hi @nperez, @aho,

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

Assignee
Assign to
Time tracking