bert gunter gunterbertongenecom outer trades space speed vectorize calculations perform loops underlying c code apply family functions eapplymapply rapply base r versions missed others packages basically efficiently written looping functions may may offer much speedup explicit loops said greatest advantage elegance code readability functional programming rather procedural programming constructs also said vectorizing calculations central theme r takes getting used know general prescriptions still learning finally please heed rolands rhelps advice provide small reproducible example want specific help bert gunter original message rhelpbouncesrprojectorg mailtorhelpbouncesrprojectorg behalf roland rau sent thursday august 07 2008 222 pm rcoder cc rhelprprojectorg subject r long run time loop operation matrix fill hi rcoder rcoder wrote hi everyone im running code containing outer inner loop fill cells 2500x1500 results matrix left program running overnight still running checked 17 hours later tested operation smaller matrix executes fine believe nothing wrong code wondering normal program execution speed operation p4 2gb ram loops one strengths r would say least explicit ones many books manuals r devote considerable space whole object view vectorizing calculations general strategies avoid loops r dont know actual program probably applying rather complicated function cell matrix code mymatrix matrixrep01 25001500 ncol1500 systemtime 1nrowmymatrix j 1ncolmymatrix mymatrixij ij 1000 catin cat output omitted took user system elapsed 13909 5556 19942 seconds best strategy usually avoid loops example obtaining results could achieved systemtime roland outerx12500 y11500 funfunctionab ab user system elapsed 025 009 034 quite speedup would say generally using outer apply family apply tapply lapply sapply forget one perform miracles terms speed allows also express ideas elegant ways opinion admit though takes grasp various concepts also still learning maybe could supply small working code example posting guide suggests might give help specific needs hope helps roland ______________________________________________ rhelprprojectorg mailing list httpsstatethzchmailmanlistinforhelp please read posting guide httpwwwrprojectorgpostingguidehtml provide commented minimal selfcontained reproducible code ______________________________________________ rhelprprojectorg mailing list httpsstatethzchmailmanlistinforhelp please read posting guide httpwwwrprojectorgpostingguidehtml provide commented minimal selfcontained reproducible code thu 07 aug 2008 145230 0700 r long run time loop operation matrix fill