title: How to transform Array[(Double, Double)] into Array[Double] in Scala?
body: <p>I'm using MLlib of Spark (v1.1.0) and Scala to do k-means clustering applied to a file with points (longitude and latitude).
  My file contains 4 fields separated by comma (the last two are the longitude and latitude).</p>
  
  <p>Here, it's an example of k-means clustering using Spark:
  <a href="https://spark.apache.org/docs/1.1.0/mllib-clustering.html" rel="nofollow">https://spark.apache.org/docs/1.1.0/mllib-clustering.html</a> </p>
  
  <p>What I want to do is to read the last two fields of my files that are in a specific directory in HDFS, transform them into an <code>RDD&lt;Vector&gt;</code> o use this method in KMeans class:
  <code>train(RDD&lt;Vector&gt; data, int k, int maxIterations)</code></p>
  
  <p>This is my code:</p>
  
  <p><code>val data = sc.textFile("/user/test/location/*")
   val parsedData = data.map(s =&gt; Vectors.dense(s.split(',').map(fields =&gt; (fields(2).toDouble,fields(3).toDouble))))</code></p>
  
  <p>But when I run it in spark-shell I get the following error:</p>
  
  <blockquote>
    <p>error: overloaded method value dense with alternatives: (values:
    Array[Double])org.apache.spark.mllib.linalg.Vector  (firstValue:
    Double,otherValues: Double*)org.apache.spark.mllib.linalg.Vector
    cannot be applied to (Array[(Double, Double)])</p>
  </blockquote>
  
  <p>So, I don't know how to transform my Array[(Double, Double)] into Array[Double]. Maybe there is another way to read the two fields and convert them into <code>RDD&lt;Vector&gt;</code>, any suggestion?</p>