title: understanding difference in results between dplyr group_by vs tapply
body: <p>I was expecting to see the same results between these two runs, and they are different. Makes me question if I really understand what how the dplyr code is working (I have read pretty much everything I can find about dplyr in the package and online). Can anyone explain why the results are different, or how to obtain similar results?</p>
  
  <pre><code>library(dplyr)
  x &lt;- iris
  x &lt;- x %.%
      group_by(Species, Sepal.Width) %.%
      summarise (freq=n()) %.%
      summarise (mean_by_group = mean(Sepal.Width))  
  print(x)
  
  x &lt;- iris
  x &lt;- tapply(x$Sepal.Width, x$Species, mean)
  print(x)
  </code></pre>
  
  <p>Update: I don't think this is the most efficient way to do this, but the following code gives a result that matches the tapply approach. Per Hadley's suggestion, I scrutinized the results line by line, and this is the best I could come up with using dplyr</p>
  
  <pre><code>library(dplyr)
  x &lt;- iris
  x &lt;- x %.%
      group_by(Species, Sepal.Width) %.%
      summarise (freq=n()) %.%
      mutate (mean_by_group = sum(Sepal.Width*freq)/sum(freq)) %.%
  print(x)
  </code></pre>
  
  <p>Update: for some reason I thought I had to group all variables I wanted to analyse, which is what sent things in the wrong direction. This is all I needed, which is closer to the examples in the package. </p>
  
  <pre><code>x &lt;- iris %.%
      group_by(Species) %.%
      summarise(Sepal.Width = mean(Sepal.Width))
  print(x)
  </code></pre>