Skip to content

Commit

Permalink
Fix count() method for matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Feb 13, 2024
1 parent 50358d6 commit 86dab39
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/count.R
Expand Up @@ -28,8 +28,11 @@ setMethod(
definition = function(x, f, margin = 1, negate = FALSE, na.rm = FALSE, ...) {
assert_function(f)
if (negate) f <- Negate(f)
x <- apply(X = x, MARGIN = margin, FUN = f, ...)
## apply() returns an array of dimension c(n, dim(X)[MARGIN])
x <- apply(X = x, MARGIN = margin, FUN = f, ..., simplify = TRUE)
## If simplify is TRUE:
## apply() returns an array of dimension c(n, dim(X)[MARGIN]) if n > 1
## apply() returns a vector if n == 1 and MARGIN has length 1
if (is.null(dim(x))) x <- matrix(x, nrow = 1)
colSums(x, na.rm = na.rm)
}
)

0 comments on commit 86dab39

Please sign in to comment.