Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 622
boY Avatar asked Jan 28 '26 12:01

boY


2 Answers

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.

like image 172
IRTFM Avatar answered Jan 30 '26 04:01

IRTFM


You can use package Rmpfr for arbitrary precision

dig <- mpfr("625075741017804806")
print(dig, 18)
# 1 'mpfr' number of precision  60   bits 
# [1] 6.25075741017804806e17
like image 20
Rorschach Avatar answered Jan 30 '26 02:01

Rorschach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!