1

For manipulating ID's that are given as character I tried the following:

> a <- "603144790381830143"
> as.numeric(a)
[1] 6.031448e+17
> as.character(as.numeric(a))
[1] "603144790381830144"

I use:

R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

Now needless to say this is unexpected behaviour (for me). Is there something I should be aware of in handling doubles?

  • OK, but then I would expect another outcome for the following `> a <- "603144790381830143"` `> options(digits = 22) ; as.numeric(a)` `[1] 603144790381830144` – Michel Metselaar Jun 01 '15 at 12:02
  • It seems like a floating points rounding issue. Every double that has more than 17 digits will be represented differently after the 17th digit. See for example `70000000000000000000000`. It probably related to `.Machine$double.eps`. Either way, take a look [here](http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) – David Arenburg Jun 01 '15 at 12:25

1 Answers1

1

I fixed it using the bit64 package:

library(bit64)
> as.character(as.integer64(a))
[1] "603144790381830143"