title: Spark Dataset - Average function
body: <p>I'm using Spark with Scala, and trying to find the best way to group <code>Dataset</code> by key, and get average + sum together. </p>
  
  <p>For example,</p>
  
  <ul>
  <li>I have <code>Dataset[Player]</code> , and <code>Player</code> consists of: playerId , yearSignup, level , points.</li>
  <li>I want to group this dataset by yearSignup , and to calculate for every year: sum of points, and average level. </li>
  <li>So with <code>groupByKey(p=&gt;p.yearSignup)</code> , and <code>reduceGroups(p1,p2)</code> , I can get the sum of points: <code>(p1.points ++ p2.points)</code> with <code>reduceLeft</code>.</li>
  </ul>
  
  <p>But how to get the average level? Should I sum it first, and after that group again and divide it?
  Or there is another way to do it together.</p>