title: Sparklyr: How to attach a group by to invoke method?
body: <p>I have this Spark table:</p>
  
  <pre><code>xydata
  y: num 11.00 22.00 33.00 ...
  x0: num 1.00 2.00 3.00 ...
  x1: num 2.00 3.00 4.00 ...
  ...
  x788: num 2.00 3.00 4.00 ...
  </code></pre>
  
  <p>and a handle named <code>xy_df</code> that is connected to this table.</p>
  
  <p>I want to <code>invoke</code> the <code>selectExpr</code> function to calculate the <code>mean</code>, something like:</p>
  
  <pre><code>xy_centered &lt;- xy_df %&gt;%  
      spark_dataframe() %&gt;% 
      invoke("selectExpr", list("( y0-mean(y0) ) AS y0mean"))
  </code></pre>
  
  <p>which is also applicable to all other columns.</p>
  
  <p>But when I run it, it gives this error:</p>
  
  <pre><code>Error: org.apache.spark.sql.AnalysisException: expression 'y0' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
  </code></pre>
  
  <p>I know this happens because, in common SQL rules, I didn't put a <code>GROUP BY</code> clause for columns contained in the aggregate function (<code>mean</code>). How do I put the <code>GROUP BY</code> to the <code>invoke</code> method?</p>
  
  <p>Previously, I manage to do complete the purpose using another way, which is by:</p>
  
  <ol>
  <li>Calculate the <code>mean</code> of each column by <code>summarize_all</code></li>
  <li>Collect the <code>mean</code> inside R</li>
  <li>Apply this mean using <code>invoke</code> and <code>selectExpr</code></li>
  </ol>
  
  <p><a href="https://stackoverflow.com/a/43614889/7913448">as explained in this answer</a>, but now I'm trying to speed up the execution time a bit by putting all operation inside the Spark itself, without retrieving anything to R.</p>
  
  <p>My Spark version is 1.6.0</p>