4

R is changing the value of big numeric values.

Example: 10050020002827959, 1907011129146780214

I've already tried to change the digits option based on a similar question, but it didn't work.

c(10050020002827959,  1907011129146780214)

The expected output should be the numbers in the vector, but it's returning

[1] 10050020002827960  1907011129146780160
M--
  • 25,431
  • 8
  • 61
  • 93
  • 1
    This is certainly related to https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal, namely this is an intersection of 32-bit integers and floating-point issues. – r2evans Jul 31 '19 at 18:37
  • 4
    Matheus, while you can control what is *displayed* by using options `scipen` and `digits`, that does not change the internal storage of the values. Because of IEEE-754 (and https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f), with numbers that large you are highly likely to lose accuracy of the lowest digits. As soon as 64-bit integers are native in R, you will be good, but until then you might need to use the `bit64` package, as in `bit64::as.integer64("10050020002827959")` (it must be introduced as a string due to R's order of evaluation). – r2evans Jul 31 '19 at 18:44
  • https://stackoverflow.com/questions/22466328/how-to-work-with-large-numbers-in-r – M-- Jul 31 '19 at 18:46
  • https://stackoverflow.com/questions/32339636/long-numbers-as-a-character-string – M-- Jul 31 '19 at 18:48

0 Answers0