Parallel foreach with my defined function in R
<p>I'd like to parallel the process below utilizing foreach in R. The process is to compare the value of column 'a' with the values of column 'b' and 'c'. if it these two values, set the flag column to TRUE, otherwise set it to FALSE. I have defined a sample dataset and I have written a function to do the comparison. I understand the function implementation is not appropriate for this a parallel process because of different return time for different nodes. So I'd appreciate if you help me how to modify the function and how to get my desired result in by running it in parallel.</p>

<pre><code>a &lt;- sample(seq(1:30),10)
b &lt;- sample(seq(20:30),10)
c &lt;- sample(seq(1:20),10)
data &lt;- cbind(id,a,b,c)
data &lt;- as.data.frame(data)

setFlag &lt;- function(id ,data){
  if(data[id]$a &gt; df[id]$b  &amp;  data[id]$a &lt; data[id]$c){
    flag &lt;- TRUE
    }else{
    flag &lt;- FALSE
    }
  return(flag)
}

NUM_OF_PROCESSOR &lt;- 6
cluster &lt;- makeCluster(NUM_OF_PROCESSOR, type = "SOCK")
cluster &lt;- registerDoSNOW(cluster)

data$flag &lt;- foreach(i=1:10, .combine = 'c') %dopar% setFlag(i, data)
</code></pre>