What is integer overflow in R and how can it happen?

前端 未结 4 1394
粉色の甜心
粉色の甜心 2020-11-28 08:36

I have some calculation going on and get the following warning (i.e. not an error):

Warning messages:
1: In sum(myvar, na.rm = T) :
Integer overflow - use s         


        
4条回答
  •  萌比男神i
    2020-11-28 09:12

    What's the max length of integer or numeric?

    Vectors are currently indexed with an integer, so the max length is given by .Machine$integer.max. As DWin noted, all versions of R currently use 32-bit integers, so this will be 2^31 - 1, or a little over 2 billion.

    Unless you are packing some serious hardware (or you are reading this in the future; hello from 2012) you won't have enough memory to allocate vectors that long.

    I remember a discussion where R-core (Brian Ripley, I think) suggested that the next step could be to index vectors with the mantissa of doubles, or something clever like that, effectively giving 48-bits of index. Sadly, I can't find that discussion.


    In addition to the Rmpfr package, if you are suffering integer overflow, you might want to try the int64 package.

提交回复
热议问题