title: run a for loop in parallel in R
body: <p>I have a for loop that is something like this:</p>
  
  <pre><code>for (i=1:150000) {
     tempMatrix = {}
     tempMatrix = functionThatDoesSomething() #calling a function
     finalMatrix =  cbind(finalMatrix, tempMatrix)
  
  }
  </code></pre>
  
  <p>Could you tell me how to make this parallel ?</p>
  
  <p>I tried this based on an example online, but am not sure if the syntax is correct. It also didn't increase the speed much.</p>
  
  <pre><code>finalMatrix = foreach(i=1:150000, .combine=cbind) %dopar%  {
     tempMatrix = {}
     tempMatrix = functionThatDoesSomething() #calling a function
  
     cbind(finalMatrix, tempMatrix)
  
  }
  </code></pre>