Hi Folks, Compare print(1234567890,digits=4) # [1] 1.235e+09 print(1234567890,digits=5) # [1] 1234567890 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 ------------------------------
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] 1234567890If 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.
>>>>> "TH" == Ted Harding <Ted.Harding at manchester.ac.uk> >>>>> on Tue, 31 Mar 2009 13:59:41 +0100 (BST) writes:TH> Hi Folks, TH> Compare TH> print(1234567890,digits=4) TH> # [1] 1.235e+09 TH> print(1234567890,digits=5) TH> # [1] 1234567890 TH> Granted that TH> digits: a non-null value for 'digits' specifies the minimum TH> number of significant digits to be printed in values. TH> how does R decide to switch from the "1.235e+09" (rounded to TH> 4 digits, i.e. the minumum, in "e" notation) to "1234567890" (the TH> complete raw notation, 10 digits) when 'digits' goes from 4 to 5? that's easy (well, as I'm one of the co-implementors ...) : One of the design ideas has been to use "e"-notation only when it's shorter (under the constraints given by 'digits'), i.e., 1.2346e+09 is not shorter (but has less information) than 1234567890 hence the latter is chosen. There are quite a few cases, and constraints (*) that apply simultaneously, such that sometimes the default numeric formatting may seem peculiar, but I hope that in the mean time we have squished all real bugs here. *) such as platform (in)dependency; S - back-compatibility, .. Best regards, Martin Maechler, ETH Zurich