title: %dopar% in R does not work properly
body: <p>I just start to use the foreach and %dopar% methodes for parallel processing in R , but the results I'm getting are confusing and not the same as a for loop; here is the code I used to test those methodes and resultes I'm getting:  </p>
  
  <pre><code>library(plyr); library(doParallel); library(foreach)
  
  cs &lt;- makeCluster(2)
  registerDoParallel(cs)
  
  sfor_start &lt;- Sys.time()
  s_for=as.numeric()
  for (i in 1:1000) {
    s_for[i] = sqrt(i)
  }
  print(Sys.time() - sfor_start)
  
  sdopar_start &lt;- Sys.time()
  sdopar=as.numeric()
  foreach(k=1:1000) %dopar% {
    sdopar[k] = sqrt(k)
  }
  print(Sys.time() - sdopar_start)
  </code></pre>
  
  <p>And here the results:</p>
  
  <pre><code>&gt; s_for[1:10]; sdopar[1:10]
   [1] 1.000000 1.414214 1.732051 2.000000 2.236068 2.449490 2.645751 2.828427 3.000000 3.162278
   [1] NA NA NA NA NA NA NA NA NA NA
  </code></pre>
  
  <p>Thanks in advance :) </p>