On Sat, Oct 6, 2012 at 3:23 PM, Bert Gunter <gunter.ber...@gene.com> wrote: > But the OP should not be doing this **at all.** He apparently has not > bothered to read the Intro to R tutorial as he appears not to know > about vectorized calculations. > > -- Bert >
I don't really think that's relevant or constructive here. Yes, it would be more idiomatic, as I and Rui already noted, to vectorize _this_ trivial example, but it obviously is just a minimal example. If the OP really wanted the result 0.02, 0.04, etc., and vectorization really was the issue at hand, we would have just directed him to seq(0.02, 1.00, 0.02) and that would have been that. The meat of the question -- which I feel the OP nicely isolated -- was the eternally surprising behavior of floating point numbers, specifically in regards to vector subsetting. It's a fact of life that many of us have seen before and know to deal with, but it's surprising and profoundly counterintuitive for beginning programmers. So much so, in fact, that the Python folks none too recently considered changing the language so that non-integer literals would use infinite precision (or at least accurate decimal implementations). It didn't really get off the ground, but it was a serious consideration by several intelligent people. Vectorization is orthogonal to all that and rather than berating the OP for his question and asserting that he "hasn't bothered," I would re-commend him for a well posed and deep question, though perhaps he didn't know quite how deep this particular rabbit hole actually goes. It shows, to me, strong evidence of someone taking the time to isolate the problem from a larger codebase before asking the list, and I appreciate that fully. Michael ______________________________________________ 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.