[R] decimal troubles ?

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Tue May 12 10:40:10 CEST 2009


> I have some trouble with the number of decimals in R (currently R 
> 2.9.0). For instance:
> 
>  > options()$digits
> [1] 3
> 
> let me hope that I will get three digits where useful when a number is 
> printed. BUT:
> 
>  > 44.25+31.1+50
> [1] 125
> 
> No way to get the right result 125.35
> 
> Can anybody tell me what's happens ?

The digits option specifies the number of significant figures, not the 
number of decimal places.  (The help documentation on the options page 
doesn't make this clear at the moment, though it does point you to 
print.default, which describes it as setting significant digits.)

Also note that the true value is being stored, so you can retrieve it with 
explicit formatting, e.g.

x <- 44.25+31.1+50
x                       # 125
print(x, digits=5)              # 125.35

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}




More information about the R-help mailing list