title: Convert Spark's DataFrame to RDD[Vector]
body: <p>When I was trying to convert a Spark's <code>DataFrame</code> into <code>RDD[org.apache.spark.mllib.linalg.Vector]</code> using the following code:</p>
  
  <pre><code>import org.apache.spark.sql.Row
  import org.apache.spark.mllib.linalg.Vectors
  
  val df = sqlContext.createDataFrame(
    Seq((0.1, 0.2, 0.4))
  ).toDF("t1", "t2", "t3")
  
  df.rdd.map{ case Row(row: Seq[_]) =&gt;
    Vectors.dense(row.asInstanceOf[Seq[Double]].toArray)
  }.collect
  </code></pre>
  
  <p>I got a error message like this:</p>
  
  <pre><code>scala.MatchError: [0.1,0.2,0.4] (of class org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema)
  </code></pre>
  
  <p>Then I tried another method:</p>
  
  <pre><code>df.content.rdd.map{ case row =&gt;
    Vectors.dense(row.toSeq.toArray.map{
      x =&gt; x.asInstanceOf[Double]
    })
  }.collect
  </code></pre>
  
  <p>It worked out fine.</p>
  
  <p>While the first method was introduced in the <a href="https://github.com/apache/spark/blob/51b1c1551d3a7147403b9e821fcc7c8f57b4824c/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala#L373" rel="nofollow noreferrer">official version of Spark-2.2.0-SNAPSHOT</a> when converting <code>row</code> into <code>Array[Double]</code>, it did not work.</p>
  
  <p>Can anyone figure out the reason?</p>