title: How to dplyr::arrange groups within a df by the mean of group measure?
body: <p>Building off of Kara Woo's <a href="https://stackoverflow.com/a/26555424/9350837">https://stackoverflow.com/a/26555424/9350837</a> answer, I'm looking to sort my grouped df by the mean of respective groups summarized measure, <code>vizCredPrcnt</code>.</p>
  
  <p>This is my code, thus far,</p>
  
  <pre><code>credData &lt;- ReShapeAdCredSubset %&gt;%
  group_by(CredentialQ, year) %&gt;%
  summarise(vizCredPrcnt = (sum(credential_wIndiv, na.rm = TRUE) / (sum(credential_wAll, na.rm = TRUE)))) %&gt;%
  arrange(CredentialQ, year, desc(mean(vizCredPrcnt)))
  </code></pre>
  
  <p>This is the error I get,</p>
  
  <blockquote>
    <p>Error in arrange_impl(.data, dots) : 
    incorrect size (1) at position 3, expecting : 144</p>
  </blockquote>
  
  <p>This is my tibble, and a visual of the grouped mean I'm looking to sort by,</p>
  
  <p><strong>grouped tibble to arrange</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8NmNz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8NmNz.jpg" alt="enter image description here"></a></p>
  
  <p>Happy to hear your thoughts!</p>