Hi

r-help-boun...@r-project.org napsal dne 18.10.2010 11:58:06:

> Hello everyone. 
> I need some help to understand when number precision in R is set. For 
this 
> please consider the following example
> 
> 
>  for (i in c(2:length(final))){
>     sizex <- c(sizex,(final[i]-final[i-1],digits=2))) # round is used to 
remove 
> values that are too small like e-17.
>     print(round(final[i]-final[i-1],digits=2))
>   }
> 
> final[2]-final[1] return something like 4.440892e-16, which means that 
these two 
> numbers are the same. They are two but as they were derived from a 
different 
> process they are not the same for precision.
> 
> Also the line print(round(final[2]-final[1]),digits=2) returns 0 which 
is 
> correct
> 
> When the above loop stops executing inside sizex variable I find the 
value 
> 4.440892e-16 which I was not expecting.  As you can see from small code 
snippet 
> before setting the value in the sizex I try to round it. The print gives 
the 

Not having your original data I presume you expect you are rounding when 
adding to sizex but you are not

 c(2,((2^0.5)^2,digits=2))

so either you forgot round or you are not telling us the whole story

Regards
Petr

> right value but for some reason it seems that inside the loop the 
precision in 
> sizex is changed.
> 
> Can you please help me clarify that?
> 
> Best Regards
> Alex
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org 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@r-project.org 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.

Reply via email to