[R] Problem with long number (from character to numeric class)

Ben Bolker bbolker at gmail.com
Wed Feb 9 15:05:22 CET 2011


PtitBleu <ptit_bleu <at> yahoo.fr> writes:

> I have a text file with one column containing long number but stored as
> string.
> I download the file with read.table (and colClass) and the first row of this
> column is :
> 
> "095842087016731010"
> 
> As I need to make some calculations with these numbers, I tried to convert
> them using as.numeric.
> But then I get
> as.numeric("095842087016731010")
> 95842087016731008
> 

  I think you are running into the limitations of double precision
values.  Take a look at the inverse of your value and compare it
to the "eps" values in .Machine.  Then see the R wiki (search for
"precision") for alternatives for extended precision calculations.

  Ben Bolker



More information about the R-help mailing list