0

I had an issue while trying to asnwer a question.

I got this vector with large numbers:

large1 <- c(2016052016051062331, 2016062016061017838,
            2016052016051062331, 2016052016051062402,
            2016052016051062325, 2016052016051062408,
            2016052016051062325, 2016052016051062408)

As we can see there're 5 unique numbers in this numeric vector. However when I do an unique I got only 3 values. In addition, it returns different numbers.

unique(large1)
#[1] 2.016052e+18 2.016062e+18 2.016052e+18

I've tried to change the digits using options(digits = 20) but got same result:

options(digits = 20)
unique(large1)
#[1] 2016052016051062272 2016062016061017856 2016052016051062528

Any idea how to deal with it?

patL
  • 2,259
  • 1
  • 17
  • 38
  • 1
    Possible duplicate https://stackoverflow.com/questions/22466328/how-to-work-with-large-numbers-in-r and https://stackoverflow.com/questions/32368555/exactly-storing-large-integers – Ronak Shah Jun 13 '18 at 09:03
  • I saw those posts and I don't think this is a duplicate because I want unique values from a vector of large numbers. – patL Jun 13 '18 at 09:05
  • 1
    this is due to a floating point error, common in almoast all programming languages.... a possible workaround is to store the numbers as characters, an other possibility is rounding your numbers to a couple of digits. – Wimpel Jun 13 '18 at 09:05
  • Well the question itself is not a duplicate, although I accepted as duplicated – patL Jun 13 '18 at 09:14
  • 1
    Possibly the bit64 package might be useful to you. – Roland Jun 13 '18 at 09:30
  • Thank you @Roland! – patL Jun 13 '18 at 09:35

0 Answers0