Skip to content

Commit 3c268ac

Browse files
authored
Merge pull request #738 from loreabad6/main
Fix dimension loss in aggregate with exact=TRUE and na.rm=TRUE
2 parents e7e1e9c + dd7cf65 commit 3c268ac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

R/aggregate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ aggregate.stars = function(x, by, FUN, ..., drop = FALSE, join = st_intersects,
106106
new_dim = c(prod(dim(x)[1:2]), prod(dim(x)[-(1:2)]))
107107
out_dim = c(ncol(m), dim(x)[-(1:2)])
108108
if (isTRUE(list(...)$na.rm))
109-
x = lapply(x, function(y) { y[is.na(y)] = 0.0; y })
109+
x = st_as_stars(lapply(x, function(y) { y[is.na(y)] = 0.0; y }), dimensions = st_dimensions(x))
110110
agg = lapply(x, function(a) array(t(m) %*% array(a, dim = new_dim), dim = out_dim))
111111
# %*% dropped units, so to propagate units, if present we need to copy (mean/sum):
112112
d = create_dimensions(append(setNames(list(create_dimension(values = by)), geom),

0 commit comments

Comments
 (0)