title: How to compute the mean with Apache spark?
body: <p>I dispose of a list of Double stored like this :</p>
  
  <pre><code>JavaRDD&lt;Double&gt; myDoubles
  </code></pre>
  
  <p>I would like to compute the mean of this list.
  According to the <a href="http://spark.apache.org/docs/latest/mllib-linear-methods.html#linear-support-vector-machine-svm" rel="nofollow">documentation</a>, :</p>
  
  <blockquote>
    <p>All of MLlib’s methods use Java-friendly types, so you can import and call them there the same way you do in Scala. The only caveat is that the methods take Scala RDD objects, while the Spark Java API uses a separate JavaRDD class. You can convert a Java RDD to a Scala one by calling .rdd() on your JavaRDD object.</p>
  </blockquote>
  
  <p>On the same page, I see the following code :</p>
  
  <pre><code>val MSE = valuesAndPreds.map{case(v, p) =&gt; math.pow((v - p), 2)}.mean()
  </code></pre>
  
  <p>From my understanding, this is equivalent (in term of types) to </p>
  
  <pre><code>Double MSE = RDD&lt;Double&gt;.mean()
  </code></pre>
  
  <p>As a consequence, I tried to compute the mean of my <code>JavaRDD</code> like this :</p>
  
  <pre><code>myDoubles.rdd().mean()
  </code></pre>
  
  <p>However, it doesn't work and gives me the following eror : <code>The method mean() is undefined for the type RDD&lt;Double&gt;</code>. I also didn't find mention of this function in the <a href="http://spark.apache.org/docs/latest/api/scala/#org.apache.spark.rdd.RDD" rel="nofollow">RDD scala documentation</a>.
  . Is this because of a bad understanding of my side, or is this something else ?</p>