title: Automatic rounding in dplyr::summarise() function
body: <p>I am wondering if there is any easy way to specify the number of digits reported by <code>summarise</code> in <code>dplyr</code>, ideally using a native <code>dplyr</code> or other <code>tidyverse</code> function?</p>
  
  <p>Here's some toy data</p>
  
  <pre><code>library(dplyr)
  
  df &lt;- data.frame(group = rep(letters[1:2], each = 10, length.out = 40),
                   large = rnorm(40, 100, 15),
                   small = rnorm(40, 0.5, 0.02))
  </code></pre>
  
  <p>If we then summarise via </p>
  
  <pre><code>df %&gt;% group_by(group) %&gt;% summarise(mL = mean(large), mS = mean(small)) 
  </code></pre>
  
  <p>We get</p>
  
  <pre><code>#   group    mL    mS
  #   &lt;fct&gt; &lt;dbl&gt; &lt;dbl&gt;
  # 1 a     104.  0.496
  # 2 b      97.6 0.506
  </code></pre>
  
  <p>Note that without specifying any rounding the variable with the higher mean has been rounded to 1 decimal place and the variable with the smaller mean has been rounded to 3.</p>
  
  <p>Now want if we want the variable with the larger mean to also be reported to 3 decimal places? If we include a command to round like so </p>
  
  <pre><code>df %&gt;% group_by(group) %&gt;% summarise(mL = round(mean(large),3), mS = mean(small))
  </code></pre>
  
  <p>There is no change in the output</p>
  
  <pre><code>#   group    mL    mS
  #   &lt;fct&gt; &lt;dbl&gt; &lt;dbl&gt;
  # 1 a     104.  0.496
  # 2 b      97.6 0.506
  </code></pre>
  
  <p>Only if we use the <code>format()</code> function can we obtain what we are after</p>
  
  <pre><code>df %&gt;% group_by(group) %&gt;% summarise(mL = format(round(mean(large),3),3), mS = mean(small))
  
    group      mL    mS
    &lt;fct&gt; &lt;chr&gt;   &lt;dbl&gt;
  1 a     103.888 0.496
  2 b     97.626  0.506
  </code></pre>
  
  <p><strong>Is there an easier way to do this?</strong> Ideally using some kind of tidyverse function.</p>