title: Parallelize user-defined function using apply family in R
body: <p>I have a script that takes too long to compute and I'm trying to paralellize its execution.</p>
  
  <p>The script basically loops through each row of a data frame and perform some calculations as shown below:</p>
  
  <pre><code>my.df = data.frame(id=1:9,value=11:19)
  
  sumPrevious &lt;- function(df,df.id){
      sum(df[df$id&lt;=df.id,"value"])
  }
  
  for(i in 1:nrow(my.df)){
      print(sumPrevious(my.df,my.df[i,"id"]))
  }
  </code></pre>
  
  <p>I'm starting to learn to parallelize code in R, this is why I first want to understand how I could do this with an apply-like function (e.g. sapply,lapply,mapply).</p>
  
  <p>I've tried multiple things but nothing worked so far:</p>
  
  <pre><code>mapply(sumPrevious,my.df,my.df$id) # Error in df$id : $ operator is invalid for atomic vectors
  </code></pre>