title: Calculate group mean, sum, or other summary stats. and assign column to original data
body: <p>I want to calculate <code>mean</code> (or any other summary statistics of length one, e.g. <code>min</code>, <code>max</code>, <code>length</code>, <code>sum</code>) of a numeric variable ("value") within each level of a grouping variable ("group").</p>
  
  <p>The summary statistic should be assigned to a new variable which has the <em>same length</em> as the <em>original data</em>. That is, each row of the original data should have a value corresponding to the current group value - the data set should <em>not</em> be collapsed to one row per group. For example, consider group <code>mean</code>:</p>
  
  <p>Before</p>
  
  <pre><code>id  group  value
  1   a      10
  2   a      20
  3   b      100
  4   b      200
  </code></pre>
  
  <p>After</p>
  
  <pre><code>id  group  value  grp.mean.values
  1   a      10     15
  2   a      20     15
  3   b      100    150
  4   b      200    150
  </code></pre>