Good morning,
I have been developing for a few months in R and I have to make sure that the execution time of my code is not too long because I analyze big datasets.
Hence, I have been trying to use as much vectorized functions as possible.
However, I am still wondering something.
What is costly in R is not the loop itself right? I mean, the problem arises when you start modifying variables within the loop for example is that correct?
Hence I was thinking, what if you simply have to run a function on each element (you actually do not care about the result). For example to write data in a database. What should you do?
1) use mapply without storing the result anywhere?
2) do a loop over the vector and only apply f(i) to each element?
3) is there a better function I might have missed?
(that's of course assuming your function is not optimally vectorized).
What about the foreach
package? Have you experienced any performance improvement by using it?