title: Apply function to column of data frame (column is a list)
body: <p>I have a data frame with 2 columns, the first is the ID number and the second one is a list of numbers. I have defined a function which sums up the list and add 2. What I'd like to do is to do the calculation for all rows without using a for loop. I tried using apply but I can't make it work...</p>
  
  <p>Here's the code:</p>
  
  <p>The test data frame:</p>
  
  <pre><code>d1 &lt;- c(1,2,3,4,5)
  d2 &lt;- c(4,6,8)
  d3 &lt;- c(5,10)
  
  df1 &lt;- data.frame(cbind(1, I(list(d1))))
  df2 &lt;- data.frame(cbind(2, I(list(d2))))
  df3 &lt;- data.frame(cbind(3, I(list(d3))))
  df &lt;- rbind(df1, df2, df3)
  </code></pre>
  
  <p>The defined function sum2:</p>
  
  <pre><code>sum2 &lt;- function(a)
  {
    sum(unlist(a)) + 2
  }
  </code></pre>
  
  <p>How can I use apply and add a third column to df containing the calculated value?</p>
  
  <p>Thanks!</p>