title: How to fix the error "'x' and 'w' must have the same length" in summarise_all()?
body: <p>I want to use dplyr::summarise_all() and weighted.mean to calculate the weighted averages of many columns for each group. </p>
  
  <p>I tried to directly use anonymous function, but it returned an error: 
  'x' and 'w' must have the same length. I know I can use summarise() and weighted.mean, but in this way I need to specify all the column names, which is not what I want.</p>
  
  <pre><code>result = df%&gt;%
    group_by(A)%&gt;%
    summarise_all(function(x){weighted.mean(x, .$B)})
  </code></pre>
  
  <p>Here the data frame has group column A, weight column B and other columns. I expect to have weighted averages of other columns values by column B for each group in A. I hope I can do this using dplyr and weighted.mean, but I am OK with other available methods.</p>