title: Using summarise with weighted mean from dplyr in R
body: <p>I'm trying to tidy a dataset, using dplyr. My variables contain percentages and straightforward values (in this case, page views and bounce rates). I've tried to summarize them this way:</p>
  
  <pre><code>require(dplyr)
  df&lt;-df%&gt;%
     group_by(pagename)%&gt;%
     summarise(pageviews=sum(pageviews), bounceRate= weighted.mean(bounceRate,pageviews))
  </code></pre>
  
  <p>But this returns:</p>
  
  <pre><code> Error: 'x' and 'w' must have the same length
  </code></pre>
  
  <p>My dataset does not have any NA's in the both the page views and the bounce rates.
  I'm not sure what I'm doing wrong, maybe <code>summarise()</code> doesn't work with <code>weighted.mean()</code>?</p>
  
  <p>EDIT</p>
  
  <p>I've added some data:</p>
  
  <pre><code>### Source: local data frame [4 x 3]
  
  ###               pagename bounceRate pageviews
                      (chr)      (dbl)     (dbl)
  ###1                url1   72.22222      1176
  ###2                url2   46.42857       733
  ###3                url2   76.92308       457
  ###4                url3   62.06897       601
  </code></pre>