title: How do I compute weighted average using summarise_each?
body: <p>How can I compute the weighted average of all the fields in a dataset using summarise_each in dplyr? For example, let's say we want to group the <strong>mtcars</strong> dataset by <strong>cyl</strong> and compute the weighted average of all columns where the weights are taken as the <strong>gear</strong> column. I've tried the following but could not get it to work.</p>
  
  <pre><code>mtcars %&gt;% group_by(cyl) %&gt;% summarise_each(funs(weighted.mean(., gear)))
  
  # The line above gives the following output
  # Error in weighted.mean.default(c(1, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2), 4.15555555555556) : 
  # 'x' and 'w' must have the same length
  </code></pre>
  
  <p>Thanks in advance for your help!</p>