From ligges@statistik.uni-dortmund.de  Tue Aug  6 07:58:54 2002
From: ligges@statistik.uni-dortmund.de (ligges@statistik.uni-dortmund.de)
Date: Tue, 6 Aug 2002 08:58:54 +0200 (MET DST)
Subject: options(digits) (PR#1879)
Message-ID: <200208060658.IAA20295@pubhealth.ku.dk>

gordong@epa.nsw.gov.au wrote:
> 
>                 [this message needed manual improvement by the mailing list
>                  administrator since it was `HTMLified' .. ``please do not'']
> 
> Apologies for bothering you about a fairly trivial matter. I have been
> getting some inconsistencies with the display digits in R V1.5.  I have been
> using the hypergeometric distribution function, and have found that when
> printing out the results from this function the display does not seem to
> correspond to the number of digits requested in the options settings. Maybe
> this indicates that the vector hasn't been generated in the proper way, or
> something, but I thought I'd report it all the same.
> 
> [Previously saved workspace restored]
> 
> > sqrt(2)
> [1] 1.414214
> > options(digits=4)
> > sqrt(2)
> [1] 1.414
> > options(digits=3)
> > for(j in 1:30){temp[j]<-sum(dhyper(0:6, j, 30 - j, 6)[3:7])}
> > temp
>  [1] 0.0000 0.0345 0.0936 0.1691 0.2543 0.3438 0.4333 0.5195 0.6002 0.6736
> [11] 0.7389 0.7956 0.8437 0.8835 0.9157 0.9410 0.9603 0.9744 0.9844 0.9912
> [21] 0.9954 0.9979 0.9992 0.9998 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
> > sqrt(2)
> [1] 1.41
> > temp
>  [1] 0.0000 0.0345 0.0936 0.1691 0.2543 0.3438 0.4333 0.5195 0.6002 0.6736
> [11] 0.7389 0.7956 0.8437 0.8835 0.9157 0.9410 0.9603 0.9744 0.9844 0.9912
> [21] 0.9954 0.9979 0.9992 0.9998 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
> > options(digits=4)
> > temp
>  [1] 0.00000 0.03448 0.09360 0.16913 0.25435 0.34383 0.43330 0.51954 0.60018
> [10] 0.67361 0.73889 0.79558 0.84368 0.88352 0.91571 0.94100 0.96026 0.97443
> [19] 0.98444 0.99116 0.99540 0.99788 0.99917 0.99976 0.99996 1.00000 1.00000
> [28] 1.00000 1.00000 1.00000
> > sqrt(2)
> [1] 1.414
> > x<-sqrt(2)
> > x
> [1] 1.414

That's not a bug. R prints the number of significant digits, as
expected.
For the second element in your vector temp, there are four sifnificant
digits printed:
the "3448" within 0.03448.

Just try some examples:

 0.123456789   # [1] 0.1234568, seven significant digits
 options(digits=4) 
 0.123456789   # [1] 0.1235, as expected
 0.001234567   # [1] 0.001235, still 4 significant digits

So, I cannot see any bug.

Uwe Ligges


> While I'm writing, I'd like to thank all of you who are working on this R
> project. I think it is very valuable work. I have a friend who after working
> as a computer consultant for many years had to retire after having a stroke
> which left him unaffected mentally but without the use of his left hand. He
> now lives on an invalid pension, and has gone back to doing scientific work
> in his retirement. There is no way he could afford commercial software. R
> has given him the tools to do good quality graphics as required by journal
> editors without which he would not have got his papers published. There must
> be many people who have something to contribute but who work outside
> institutions and don't have the means to purchase commercial licences. And
> Third World countries should benefit greatly.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


options(digits) (PR#1879)
ligges@statistik.uni-dortmund.de