title: How to use dplyr to calculate a weighted mean of two grouped variables
body: <p>I know this must be super easy, but I'm having trouble finding the right dplyr commands to do this.  Let's say I want to group a dataset by two variables, and then summarize the count for each row.  For this we simply have:</p>
  
  <pre><code>mtcars %&gt;% group_by(cyl, mpg) %&gt;% summarize(Count = n())
  </code></pre>
  
  <p>This will generate a dataframe with 27 rows for the three variables <code>cyl</code>, <code>mpg</code>, and <code>Count</code>.  What I'd like to do next is summarize the average <code>mpg</code> for each of the three <code>cyl</code> values.  Keep in mind that each row may contain a <code>Count</code> greater than one which must be considered when calculating the average.  My data frame should have 3 rows of 2 variables <code>cyl</code>, and <code>Avg_mpg</code>.  Can someone give me the short code chuck that will do this?
  Thank you in advance.</p>