title: Indexing grouped_df object
body: <p>Trying to select a column of an object of class <code>grouped_df</code> by index gives "Error: index out of bounds". For example</p>
  
  <pre><code>x &lt;- mtcars %&gt;% group_by(am, gear) %&gt;% summarise_each(funs(sum), disp, hp, drat)
  class(x)
  #    "grouped_df" "tbl_df"     "tbl"        "data.frame"
  # For some reason the first column can be selected...
  x[1]
  #    Source: local data frame [4 x 1]
  #    Groups: am
  #    am
  #     0
  #     0
  #     1
  #     1    
  # ...but any index &gt; 1 fails
  x[2] 
  #   Error: index out of bounds
  # Coercing to data frame does the trick...
  as.data.frame(x)[2]
  #   gear
  #      3
  #      4
  #      4
  #      5
  #... and so does ungrouping
  all(ungroup(x)[2] == as.data.frame(x)[2]) # TRUE
  </code></pre>
  
  <p>This is using R version 3.1.1 and dplyr 0.3.0.2. I'm not sure whether this is a bug or intentional.. Is there any good reason why it works this way? I'd rather not have to remember to ungroup my data frames after using <code>dplyr</code> every time...</p>
  
  <p><em>Update</em> Having looked a bit further into this, my guess is that the motivation for defining <code>[.grouped_df</code> <a href="https://github.com/hadley/dplyr/blob/master/R/grouped-df.r#L63" rel="nofollow">this way</a> is for the groups to be preserved when calling e.g. <code>x[1:3]</code> (which works). However, when the index is not part of the grouping variables, the error above is thrown. Perhaps it could be modified so that in this case it calls <code>[.tbl_df</code> and throws a warning at the same time...</p>
  
  <p><em>Update 2</em> <code>[.grouped_df</code> has been modified in the development version of dplyr (0.3.0.9000). It still throws an error, but is more clear now, specifying which grouping variables were not included. </p>
  
  <pre><code>x[2]
  # Error in `[.grouped_df`(x, 2) : 
  #     cannot group, grouping variables 'am' not included
  </code></pre>
  
  <p>The best solution I've found so that my code doesn't crash in this situation, is to include <code>%&gt;% ungroup</code> at the end of the <code>dplyr</code> command chain.</p>