0

Hope i am not spamming! I often try not not to loop, but sometimes, life becomes difficult without loop. Even if i often loop inside functions.

Fun1 = function(x) loop1, loop2

What's the best way to deal with or avoid loop?

Mithilesh Kumar
  • 256
  • 1
  • 3
  • 18
  • 1
    Possible dupplicate http://stackoverflow.com/questions/7142767/why-are-loops-slow-in-r – harre Nov 07 '15 at 13:29
  • 2
    @Mike Wise, please quit promulgating this myth that the `apply()` functions are different than a well programmed and designed for loop. Look for yourself at the source code of `apply` by typing that alone at the R prompt, and you will find that at its core is a for loop to iterate over the items in the list/vector/matrix etc. Vectorized functions like `sum()`, `mean()`, `colSums()`, `rowMeans()`, etc. are the reason that that you would "avoid loops." The `apply()` class of functions are only helper functions to reduce typing and perhaps increase clarity, if a programmer is R-centric. – Forrest R. Stevens Nov 07 '15 at 14:30
  • Uh, okay. Properly chastised and will delete comment. – Mike Wise Nov 07 '15 at 14:31
  • I didn't mean to come off short... I was honestly trying to be helpful. I think I was responding more to how this question manages to still be asked every day in various fora and people refuse to put in any leg work to search for an answer. But the fact they find contradictory information when they do search probably reinforces this behavior. :) – Forrest R. Stevens Nov 07 '15 at 14:37

0 Answers0