NAs produced by integer overflow + R on linux

后端 未结 3 1286
栀梦
栀梦 2021-01-13 18:56

I\'m running an R script on UNIX based system , the script contain multiplication of large numbers , so the results where NAs by integer overflow , but when i run the same s

3条回答
  •  无人共我
    2021-01-13 19:15

    Can you cast your integers to floating-point numbers in order to use floating-point math for the computations?

    For example:

    > x=as.integer(1000000)
    > x*x
    [1] NA
    Warning message:
    In x * x : NAs produced by integer overflow
    > x=as.numeric(1000000)
    > x*x
    [1] 1e+12
    

    As an aside, it is not entirely clear why the warning would appear in one environment but not the other. I first thought that 32-bit and 64-bit builds of R might be using 32-bit and 64-bit integers respectively, but that doesn't appear to be the case. Are both your environments configured identically in terms of how warnings are displayed?

提交回复
热议问题