title: R, dplyr - combination of group_by() and arrange() does not produce expected result?
body: <p>when using dplyr function <code>group_by()</code> and immediately afterwards <code>arrange()</code>, I would expect to get an output where data frame is ordered <em>within</em> groups that I stated in <code>group_by()</code>. My reading of documentation is that this combination should produce such a result, however when I tried it this is not what I get, and googling did not indicate that other people ran into the same issue. Am I wrong in expecting this result?</p>
  
  <p>Here is an example, using the R built-in dataset ToothGrowth:</p>
  
  <pre><code>library(dplyr)
  ToothGrowth %&gt;%
    group_by(supp) %&gt;%
    arrange(len)
  </code></pre>
  
  <p>Running this will produce a data frame where the whole data frame is ordered according to <code>len</code> and not within <code>supp</code> factors.</p>
  
  <p>This is the code that produces the desired output:</p>
  
  <pre><code>ToothGrowth %&gt;%
    group_by(supp) %&gt;%
    do( data.frame(with(data=., .[order(len),] )) )
  </code></pre>