0

Dear stackoverflow community, I work with a dataset with very large numbers, which represent customer id's. If I want to change these from string to as.character the following happens:

alpha<-"2510607126325391401"
beta<-as.numeric(alpha)
print(beta, digits=22)
[1] 2510607126325391360.000

Which is clearly not identical, does somebody now how to resolve this issue? Thank you in advance, Best, Alec Minnema

James
  • 65,548
  • 14
  • 155
  • 193
  • 1
    It is not clear what you are wanting to do. Are you wanting to keep them as strings or do numerical calculations on them? – James Aug 11 '14 at 13:45
  • Do you want to change them from string to numeric? The string is already character. – John Paul Aug 11 '14 at 13:47
  • 1
    If it's a customer ID, sounds like it would be better to keep it as a character. R numeric values do not have the precision to hold that many digits for an integer. – MrFlick Aug 11 '14 at 13:59
  • First check str(alpha), and find if it is chr or num in the first place. Those are indeed character at the beginning – won782 Aug 11 '14 at 14:15
  • Possibly: http://stackoverflow.com/questions/11441035/weird-error-in-r-when-importing-integer-with-many-digits/11441427#11441427 – Blue Magister Aug 11 '14 at 20:32

1 Answers1

2

Apart from the fact that it may not be a good idea to represent customer id's in a numeric value, you can use the class bigz from package gmp:

require(gmp)
alpha<-"2510607126325391401"
as.bigz(alpha)
shadow
  • 21,823
  • 4
  • 63
  • 77