On Thu, Mar 01, 2012 at 04:55:55PM -0500, Sarah Goslee wrote:

> Of course there's rounding error: your computer can't

> store those decimal numbers precisely. See R FAQ 7.31 for

> details.

>

> See also:

> sum(10*c(-0.2, 0.8, 0.8, -3.2, 1.8)) / 10

Hi.

This is 0. This works without rounding for one digit precision,

since we always have i == 10*(i/10). Already for two digits, we

may have i != 100*(i/100). So, for example

sum(100*c(0.28, -0.21, 0.66, -0.73))/100

[1] 3.552714e-17

Rounding the multiples to be integers yields the expected result

sum(round(100*c(0.28, -0.21, 0.66, -0.73)))/100

[1] 0

Petr Savicky.

______________________________________________

[hidden email] mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.