Skip to content

Commit

Permalink
Merge pull request #738 from loreabad6/main
Browse files Browse the repository at this point in the history
Fix dimension loss in aggregate with exact=TRUE and na.rm=TRUE
  • Loading branch information
edzer authored Feb 13, 2025
2 parents e7e1e9c + dd7cf65 commit 3c268ac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ aggregate.stars = function(x, by, FUN, ..., drop = FALSE, join = st_intersects,
new_dim = c(prod(dim(x)[1:2]), prod(dim(x)[-(1:2)]))
out_dim = c(ncol(m), dim(x)[-(1:2)])
if (isTRUE(list(...)$na.rm))
x = lapply(x, function(y) { y[is.na(y)] = 0.0; y })
x = st_as_stars(lapply(x, function(y) { y[is.na(y)] = 0.0; y }), dimensions = st_dimensions(x))
agg = lapply(x, function(a) array(t(m) %*% array(a, dim = new_dim), dim = out_dim))
# %*% dropped units, so to propagate units, if present we need to copy (mean/sum):
d = create_dimensions(append(setNames(list(create_dimension(values = by)), geom),
Expand Down

0 comments on commit 3c268ac

Please sign in to comment.