title: Dplyr function to compute average, n, sd and standard error
body: <p>I find myself writing this bit of code all the time to produce standard errors for group means ( to then use for plotting confidence intervals).  </p>
  
  <p>It would be nice to write my own function to do this in one line of code, though. I have read the <a href="https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html" rel="nofollow noreferrer">nse</a> vignette in dplyr on non-standard evaluation and <a href="https://medium.com/optima-blog/writing-your-own-dplyr-functions-a1568720db0d" rel="nofollow noreferrer">this blog post</a> as well. I get it <em>somewhat</em>, but I'm too much of a noob to figure this out on my own.  Can anyone help out? Thanks. </p>
  
  <pre><code>var1&lt;-sample(c('red', 'green'), size=10, replace=T)
  var2&lt;-rnorm(10, mean=5, sd=1)
  df&lt;-data.frame(var1, var2)
  df %&gt;% 
  group_by(var1) %&gt;% 
  summarize(avg=mean(var2), n=n(), sd=sd(var2), se=sd/sqrt(n))
  </code></pre>