Re: [R] understanding integer divide (%/%)

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Wed 03 Jan 2007 - 13:29:14 GMT


This is due to the internal representation of 0.1, which is not exactly 0.1 but very close to it. If you want to do an integer divide, you should only use integers to divide with.

Cheers,

Thierry



ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest

Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance

Gaverstraat 4

9500 Geraardsbergen

Belgium

tel. + 32 54/436 185

Thierry.Onkelinx@inbo.be

www.inbo.be  

Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt

A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] Namens Jeffrey Prisbrey Verzonden: woensdag 3 januari 2007 14:21 Aan: r-help@stat.math.ethz.ch
Onderwerp: [R] understanding integer divide (%/%)

I am confused about why the following occurs:

> version

               _                           
platform       i386-pc-mingw32             
arch           i386                        
os             mingw32                     
system         i386, mingw32               
status                                     
major          2                           
minor          4.0                         
year           2006                        
month          10                          
day            03                          
svn rev        39566                       
language       R                           
version.string R version 2.4.0 (2006-10-03)
> 1 %/% 0.1

[1] 9
> 10 %/% 1

[1] 10
>

This effect led me into an trap when I tried to classify a set of proportions based on the first decimal place by integer dividing by 0.1. Can someone explain why this behavior occurs and give me an insight into how to predict it?

Thanks,
-- Jeff



R-help@stat.math.ethz.ch 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.

R-help@stat.math.ethz.ch 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. Received on Thu Jan 04 01:30:51 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 Jan 2007 - 00:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.