[R] Division ?

Bernardo Rangel Tura tura at centroin.com.br
Sun May 3 22:46:49 CEST 2009


On Sat, 2009-05-02 at 10:34 -0700, bogdanno wrote:
> It seems division with numbers bigger than 10 000 000 doesn't work
>  20000000/21
> [1] 952381
> > 55555555/23
> [1] 2415459
> 
> Thank you


Hi bogdanno

First of all look this

> all.equal(21*20000000/21,20000000)
[1] TRUE

So de division work correctly

but if I type

> all.equal(952381*21,20000000)
[1] "Mean relative difference: 5e-08"

It's not means R division don't work correctly if you use the command
> format(20000000/21,digits=22)
[1] "952380.952380952

So the result: 952381 is a round number not a real result of division.
This occur because R print only 7 significants digits in numbers, if you
test
> all.equal(21*952380.952380952,20000000)
[1] TRUE

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil




More information about the R-help mailing list