Skip to content

sample() issue

8 messages · cory n, David Winsemius, Peter Langfelder +4 more

#
On Dec 20, 2010, at 2:04 PM, cory n wrote:

            
Read the FAQ:
 > 25000*(1-.55)-11250
[1] -1.818989e-12
 > 25000*(1-.55)< 11250
[1] TRUE

?round
?all.equal
?zapsmall

  
    
#
See FAQ 7.31: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

And try this:

25000*(1-.55) - 11250

25000*.45 - 11250

Notice a difference?

Best,

--
Wolfgang Viechtbauer
Department of Psychiatry and Neuropsychology
School for Mental Health and Neuroscience
Maastricht University, P.O. Box 616
6200 MD Maastricht, The Netherlands
Tel: +31 (43) 368-5248
Fax: +31 (43) 368-8689
Web: http://www.wvbauer.com


----Original Message----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of cory n Sent: Monday, December 20, 2010 20:04
To: r-help at r-project.org
Subject: [R] sample() issue
#
On Mon, Dec 20, 2010 at 11:04 AM, cory n <corynissen at gmail.com> wrote:
Let me make a wild guess:
[1] 11249
[1] 11250
[1] -1.818989e-12
[1] 0


I'm guessing that the machine representation of 0.55 is off by
something like 1e-16, which gets
multiplied by a lot (25000) and this is enough for the floor (or
whatever rounding the internal code uses) to make it 11249. The morale
of the story is do not multiply non-exact numbers by huge constants or
you may get small inaccuracies.

Peter
#
See FAQ 7.31

Then try
Hope this is helpful,

Dan


Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
#
Trying to make the fastest referal to FAQ 7.31 is becoming quite a sport around here. David beat us all to it on this round. Chances are there will be many more rounds to come.

Best,

Wolfgang

----Original Message----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Jorge Ivan Velez Sent: Monday, December 20, 2010 20:42
To: cory n
Cc: R mailing list
Subject: Re: [R] sample() issue