Skip to content
Prev 54657 / 63424 Next

sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31

Just following up on this old thread since matrixStats 0.53.0 is now
out, which supports this use case:
[1] NA
Warning message:
In sum(x) : integer overflow - use sum(as.numeric(.))
[1] 2147483648
num 2.15e+09

No coercion is taking place, so the memory overhead is zero:
Rprofmem memory profiling of:
y <- matrixStats::sum2(x, mode = "double")

Memory allocations:
      bytes calls
total     0

/Henrik

On Fri, Jun 2, 2017 at 1:58 PM, Henrik Bengtsson
<henrik.bengtsson at gmail.com> wrote: