[R] "digits" in round()

Duncan Murdoch murdoch at stats.uwo.ca
Tue Mar 31 15:11:24 CEST 2009


On 3/31/2009 8:59 AM, (Ted Harding) wrote:
> Hi Folks,
> 
> Compare
> 
>   print(1234567890,digits=4)
> # [1] 1.235e+09
>   print(1234567890,digits=5)
> # [1] 1234567890

If printing in scientific notation takes up as much space or more than 
printing in regular notation, then regular notation will be used.

In this case the 5 digit scientific notation output of 1.2346e+09 takes 
10 characters, so the 10 character simple format is used instead.

The reason for this rule is that regular notation gives more information 
about the number.  If you had wanted to use 10 chars but be less 
expressive you would have used an explicit format.

Duncan Murdoch

> Granted that
> 
>   digits: a non-null value for 'digits' specifies the minimum
>           number of significant digits to be printed in values.
> 
> how does R decide to switch from the "1.235e+09" (rounded to
> 4 digits, i.e. the minumum, in "e" notation) to "1234567890" (the
> complete raw notation, 10 digits) when 'digits' goes from 4 to 5?
> 
> Thanks,
> Ted.
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 31-Mar-09                                       Time: 13:59:37
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list