title: Summarizing multiple columns with dplyr?
body: <p>I'm struggling a bit with the dplyr-syntax. I have a data frame with different variables and one grouping variable. Now I want to calculate the mean for each column within each group, using dplyr in R.</p>
  
  <pre><code>df &lt;- data.frame(
      a = sample(1:5, n, replace = TRUE), 
      b = sample(1:5, n, replace = TRUE), 
      c = sample(1:5, n, replace = TRUE), 
      d = sample(1:5, n, replace = TRUE), 
      grp = sample(1:3, n, replace = TRUE)
  )
  df %&gt;% group_by(grp) %&gt;% summarise(mean(a))
  </code></pre>
  
  <p>This gives me the mean for column "a" for each group indicated by "grp".</p>
  
  <p>My question is: is it possible to get the means for each column within each group at once? Or do I have to repeat <code>df %&gt;% group_by(grp) %&gt;% summarise(mean(a))</code> for each column?</p>
  
  <p>What I would like to have is something like</p>
  
  <pre><code>df %&gt;% group_by(grp) %&gt;% summarise(mean(a:d)) # "mean(a:d)" does not work
  </code></pre>