title: How to convert RDD[Row] to RDD[Vector]
body: <p>I'm trying to implement k-means method using scala.
  I created a RDD something like that</p>
  
  <pre><code>val df = sc.parallelize(data).groupByKey().collect().map((chunk)=&gt; {
    sc.parallelize(chunk._2.toSeq).toDF()
  })
  
  val examples = df.map(dataframe =&gt;{
    dataframe.selectExpr(
      "avg(time) as avg_time",
      "variance(size) as var_size",
      "variance(time) as var_time",
      "count(size) as examples"
    ).rdd
  })
  
  val rdd_final=examples.reduce(_ union _)
  
  val kmeans= new KMeans()
  val model = kmeans.run(rdd_final)
  </code></pre>
  
  <p>With this code I obtain an error</p>
  
  <pre><code>type mismatch;
  [error]  found   : org.apache.spark.rdd.RDD[org.apache.spark.sql.Row]
  [error]  required:org.apache.spark.rdd.RDD[org.apache.spark.mllib.linalg.Vector]
  </code></pre>
  
  <p>So I tried to cast doing:</p>
  
  <pre><code>val rdd_final_Vector = rdd_final.map{x:Row =&gt; x.getAs[org.apache.spark.mllib.linalg.Vector](0)}
  
  val model = kmeans.run(rdd_final_Vector)
  </code></pre>
  
  <p>But then I obtain an error:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Double cannot be cast to org.apache.spark.mllib.linalg.Vector
  </code></pre>
  
  <p>So I'm looking for a way to do that cast, but I can't find any method.</p>
  
  <p>Any idea?</p>
  
  <p>Best regards</p>