boY
boY

Reputation: 151

Donot want large numbers to be rounded off in R

options(scipen=999)

625075741017804800

625075741017804806

When I type the above in the R console, I get the same output for the two numbers listed above. The output being: 625075741017804800

How do I avoid that?

Upvotes: 3

Views: 553

Answers (2)

IRTFM
IRTFM

Reputation: 263301

Numbers greater than 2^53 are not going to be unambiguously stored in the R numeric classed vectors. There was a recent change to allow integer storage in the numeric abscissa, however your number is larger that that increased capacity for precision:

625075741017804806 > 2^53
[1] TRUE

Prior to that change integers could only be stored up to Machine$integer.max == 2147483647. Numbers larger than that value get silently coerced to 'numeric' class. You will either need to work with them using character values or install a package that is capable of achieving arbitrary precision. Rmpfr and gmp are two that come to mind.

Upvotes: 6

Rorschach
Rorschach

Reputation: 32416

You can use package Rmpfr for arbitrary precision

dig <- mpfr("625075741017804806")
print(dig, 18)
# 1 'mpfr' number of precision  60   bits 
# [1] 6.25075741017804806e17

Upvotes: 3

Related Questions