title: difference between ddply and aggregate
body: <p>Can someone help me get the difference between aggregate and ddply with the following example:</p>
  
  <p>A data frame:</p>
  
  <pre><code>mydat &lt;- data.frame(first = rpois(10,10), second = rpois(10,10), 
                      third = rpois(10,10), group = c(rep("a",5),rep("b",5)))
  </code></pre>
  
  <p>Use aggregate to apply a function to a part of the data frame split by a factor:</p>
  
  <pre><code>aggregate(mydat[,1:3], by=list(mydat$group), mean)
    Group.1 first second third
  1       a   8.8    8.8  10.2
  2       b   6.8    9.4  13.4
  </code></pre>
  
  <p>Try to use aggregate for another function (returns an error message):</p>
  
  <pre><code>aggregate(mydat[,1:3], by=list(mydat$group), function(u) cor(u$first,u$second))
  Error in u$second : $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>Now, try the same with ddply (plyr package):</p>
  
  <pre><code>ddply(mydat, .(group), function(u) cor(u$first,u$second))
    group         V1
  1     a -0.5083042
  2     b -0.6329968
  </code></pre>
  
  <p>All tips, links, criticism are highly appreciated. </p>