FAQ 7.31 ?all.equal
On Mon, Oct 18, 2010 at 5:58 AM, Alaios <ala...@yahoo.com> wrote: > 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 > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.