Search code examples
rchardoubledecimal

Very small numbers in R


This is the first time I post something on a forum, so please be gentle. I've been programming in R for over a year now.

I'm trying to do a (mathematically very simple) statistical analysis of large datasets that come directly from a mass spectrometer. As you may know, these instruments are extremely precise and can measure very large, as well as very small voltages precisely: 50V to 0.00000000000000010V. The values are then reported to a tab-delimited file, which I can read into R.

However, at this point, I have the following problem: If I convert the data into doubles, I lose significant information. If I keep them in characters or factors, I cannot "use" them and calculate what I need to get.

Is there a work-around, so I can keep the precision AND use R? Would it be better to use a C++-based language, such as Matlab? Would Matlab be able to do this?


Solution

  • You can use Library gmp

    http://cran.r-project.org/web/packages/gmp/

    Example (Large Numbers)

    install.packages("gmp")
    library(gmp)
    largevalue <- as.bigz(2305843009213694080000000)
    largevalue 
    

    Example (Small Numbers)

    smallvalues <- asNumeric(cbind(0.0000000000000000000001,0.0000000000000000000003))
    smallvalues