[R] r: LOOPING

Vehbi Sinan Tunalioglu vehbisinan at gmail.com
Fri Jul 8 09:30:49 CEST 2005


Uwe Ligges wrote:
> Clark Allan wrote:
>>
>>i know that one should try and limit the amount of looping in R
>>programs. i have supplied some code below. i am interested in seeing how
>>the code cold be rewritten if we dont use the loops.
> 
> It is not always a good thing to remove loops (without having looked at 
> each details of the code below).
> "Compromise" is the keyword.

If you have big routines for each iteration and especially you have back
references in the data structures you are manipulating, it becomes
really _hard to translate_ loop statements to filter-map-accumulator
routines provided by R (i.e. *apply functions). I really cannot find my
way in some situations. What I did so far is to write those routines in
C. Dirty hack :(

Maybe one should write a tutorial: "Howto avoid loops in R" by giving
possible scenarios.

--vst




More information about the R-help mailing list