Display exact value of a variable in R

妖精的绣舞 提交于 2019-12-17 06:56:08

问题


> 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!


回答1:


Globally solution during all the session

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

or locally just for x:

sprintf("%.16f", x)
[1] "1.0004258921256499"



回答2:


print(x, digits=15)

or

format(x, digits=15)

or

sprintf("%.14f", x)


来源:https://stackoverflow.com/questions/17724382/display-exact-value-of-a-variable-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!