0

This doesn't require an extensive explanation. Why

as.numeric("1221008815753031681")

returns

[1] 1221008815753031680

CptNemo
  • 6,455
  • 16
  • 58
  • 107
  • https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal – r2evans Oct 15 '20 at 01:23
  • 3
    If you look at `.Machine$integer.max`, you'll see that it's likely `2147483647` (10 digits). This is the largest *strict integer* that R can store in 32-bit integers (64-bit ints are a long-sought-after feature, supported by the `bit64` package but not universally used/supported by other packages). While this 32-bit int here is only 10 digits, your number is 19 digits, clearly well outside of what R can use. For this, R defaults to giving you *a number*, which in this case is technically a `numeric` (float/double). When numbers get large, there can be rounding errors, ergo the link above. – r2evans Oct 15 '20 at 01:25
  • 2
    the question I've tagged as a duplicate goes in the opposite direction, but the reasoning (and solutions) are applicable in this case as well. – Ben Bolker Oct 15 '20 at 01:26
  • Thanks @BenBolker, that's a far better and informative dupe question – r2evans Oct 15 '20 at 01:50

0 Answers0