From e5d69ae49e7177c3e20de9a4ab8a445fd8b50559 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sat, 7 Sep 2024 13:35:50 +0200 Subject: [PATCH] Fix `fmean(c(1L, NA), na.rm = F, g = c(1L, 1L))` issue (#628). --- src/fmean.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fmean.c b/src/fmean.c index cea87e69..e5e5aa1e 100644 --- a/src/fmean.c +++ b/src/fmean.c @@ -208,7 +208,9 @@ void fmean_int_g_impl(double *restrict pout, const int *restrict px, const int n R_Free(n); } else { --pout; - for(int i = l; i--; ) pout[pg[i]] += px[i]; // Used to stop loop when all groups passed with NA, but probably no speed gain since groups are mostly ordered. + for(int i = l; i--; ) { + pout[pg[i]] += px[i] == NA_INTEGER ? NA_REAL : px[i]; // Used to stop loop when all groups passed with NA, but probably no speed gain since groups are mostly ordered. + } ++pout; for(int i = ng; i--; ) pout[i] /= pgs[i]; }