Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display exact value of a variable in R

Tags:

r

r-faq

> x <- 1.00042589212565
> x
[1] 1.000426

If I wanted to print the exact value of x, how would I do it?

Sorry if this is a dumb question. I tried Googling for "R" and "exact" or "round" but all I get are articles about how to round.

Thank you in advance!

like image 619
angryavian Avatar asked Nov 30 '22 03:11

angryavian


2 Answers

Globally solution during all the session

options(digits=16)
> x
[1] 1.00042589212565

or locally just for x:

sprintf("%.16f", x)
[1] "1.0004258921256499"
like image 74
agstudy Avatar answered Dec 05 '22 03:12

agstudy


print(x, digits=15)

or

format(x, digits=15)

or

sprintf("%.14f", x)
like image 25
Hong Ooi Avatar answered Dec 05 '22 02:12

Hong Ooi