1

I have a dataframe that has an id field with values as these two:

587739706883375310

587739706883375408

The problem is that, when I ask R to show these two numbers, the output that I get is the following:

587739706883375360

587739706883375360

which are not the real values of my ID field, how do I solve that?

For your information: I have executed options(scipen = 999) to R does not convert my number to a scientific notation. This problem also happens in R console, if I enter these examples numbers I also get the same printing as shown above.

EDIT: someone asked

dput(yourdata$id)

I did that and the result was:

c(587739706883375360, 587739706883375360, 587739706883375488, 587739706883506560, 587739706883637632, 587739706883637632, 587739706883703040)

To compare, the original data in the csv file is:

587739706883375310,587739706883375408,587739706883375450,587739706883506509,587739706883637600,587739706883637629,587739706883703070

I also did the following test with one of these numbers:

> 587739706883375408
[1] 587739706883375360
> as.double(587739706883375408)
[1] 587739706883375360
> class(as.double(587739706883375408))
[1] "numeric"
> is.double(as.double(587739706883375408))
[1] TRUE
kplt
  • 59
  • 6
  • Please dput(yourdata$id). – Christoph May 21 '18 at 13:41
  • 4
    Use a big int formula or (probably more appropriate) read the column in as a character column. Unless you're doing math with these numbers, treating them as character is probably best. – Gregor Thomas May 21 '18 at 13:43
  • 4
    This is a common problem with computers trying to emulate numbers. R by default (like many other languages) saves numbers in double-precision. This means that it can only save the first 16 digits of a number - see here: https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format – Rentrop May 21 '18 at 13:44
  • 1
    Possible duplicate of [long/bigint/decimal equivalent datatype in R](https://stackoverflow.com/questions/2053397/long-bigint-decimal-equivalent-datatype-in-r) – Rentrop May 21 '18 at 13:45

1 Answers1

1

You can use the bit64 package to represent such large numbers:

library(bit64)
as.integer64("587739706883375408")
# integer64
# [1] 587739706883375408
as.integer64("587739706883375408") + 1 
# integer64
# [1] 587739706883375409
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75