title: R: Group in sparklyr ("sum", "count distinct" , "mean")
body: <p>we have the following data hosted in the working directory:</p>
  
  <pre><code> &gt;library(sparklyr)
   &gt;library(dplyr)
  
   &gt;f&lt;-data.frame(category=c("e","EE","W","S","Q","e","Q","S"), 
            DD=c(33.2,33.2,14.55,12,13.4,45,7,3),
            CC=c(2,44,4,44,9,2,2.2,4), 
   &gt;FF=c("A","A","A","A","A","A","B","A") )
  
  &gt;write.csv(f,"D.csv")##Write in working directory
  </code></pre>
  
  <p>We  using spark commands to read the file from the Working directory</p>
  
  <pre><code>&gt;sc &lt;- spark_connect(master = "local", spark_home = "/home/tomas/spark-2.1.0-bin-hadoop2.7/", version = "2.1.0")
  
  
  &gt;df &lt;- spark_read_csv(sc, name = "data", path = "D.csv", header = TRUE, delimiter = ",")
  </code></pre>
  
  <p>I want to obtain a matrix like the following, in which is grouped by "category", sum DD, calculate the average of "CC", count different in "FF"</p>
  
  <p>It would stay like this:</p>
  
  <pre><code>  category SumDD MeanCC CountDistinctFF
     e       78.2    2             1
     EE      33.2    44.           1
     WW      14.55   4             1
     S       15      24            2
     Q       20.4    5.6           1
  </code></pre>