0

I want the number of significant figures in my whole R-code to be 15. The option:

options(digits=15) 

does not give me the output I want. It is rounding a result to the least number of significant digits. It gives me for example the output:

-1.234567890123456
-0.123456789012345

The number of significant digits of the second number is the smallest, so R sets this on 15. The first number is then by R with the same number of decimal places. This gives for the first number significant factors 16. What I want is 15 significant factors for all numbers in my output. So what I want is:

-1.23456789012345
-0.123456789012345

How can this be done for every output?

Any help is appreciated.

Henry
  • 25
  • 6
  • 1
    Do you want to _print_ numbers to 15 significant figures, or do _computations_ on 15 significant figures? – Hong Ooi Mar 15 '16 at 16:09
  • The output you show is unusual because R uses `.` as decimal separator. Please show the code that produced this output. – Roland Mar 15 '16 at 16:33
  • @Roland Yeah I'm sorry ofcourse it is a dot, but it is just a short example because the code is too long. But you can for example think of systemfit on some data. – Henry Mar 15 '16 at 17:20
  • @HongOoi The output is a collection of parameters. Based on this (rounded) output I need to do further calculations. So, I think I need to do _computations_ on 15 significant figures during my whole calculation, since this is done in this step. – Henry Mar 16 '16 at 07:41
  • This is very unusual. Consider very carefully if you really want to do this. Usually you want to compute with the highest precision possible. – Roland Mar 16 '16 at 07:52
  • @Roland I think the reasoning is the following: when I calculate 0.01-0.001 in python I get 0.009000000000000001 ? – Henry Mar 16 '16 at 07:56
  • @henry don't worry about it. Really. – Hong Ooi Mar 16 '16 at 08:03
  • @Henry OK. And that is a problem why? It's just how floating point numbers work and the precision *displayed* by the software. E.g., run `sprintf("%.20f", 0.01-0.001)` in R. – Roland Mar 16 '16 at 08:04
  • It seems that python uses 0.009000000000000001 for further calculation and R uses 0.009? This is namely the output in both cases. – Henry Mar 16 '16 at 08:11
  • @HongOoi How do you print to 15 significant figures? signif(fit$beta,15) does not give me the right result – Henry Mar 16 '16 at 09:32
  • "It seems that python uses 0.009000000000000001 for further calculation and R uses 0.009?" That's just plain wrong. Both use the floating point precision in all calculations. You are still confusing the actual value with what is printed in the console. – Roland Mar 17 '16 at 13:02
  • Thanks. I understand it now! – Henry Mar 18 '16 at 09:00

0 Answers0