isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
274 stars 26 forks source link

exact_resample with fun = 'mode' returns only NAs #47

Closed amarbler closed 3 years ago

amarbler commented 3 years ago

Hello,

I just discovered the exactextractr::exact_resample() function. It works perfectly fine with the stats "mean", "sum", "count", "min", and "max". However, it always returns only NAs when using stats "mode" or "minority", e.g.:


r = raster::raster(resolution = 2)
target = raster::shift(r, 2.5, 1)

set.seed(1111)
raster::values(r) = as.integer(round(rnorm(raster::ncell(r), 0, 1)))

unique(raster::getValues(exactextractr::exact_resample(r, target, fun = "mode")))
[1] NA
unique(raster::getValues(exactextractr::exact_resample(r, target, fun = "min")))
[1]  1  0 -3 -1 -2  2 NA -4
dbaston commented 3 years ago

Thanks for the report and test case.

amarbler commented 3 years ago

Thanks for the quick fix, it works.