title: Spark Scala: How to convert Dataframe[vector] to DataFrame[f1:Double, ..., fn: Double)]
body: <p>I just used Standard Scaler to normalize my features for a ML application. After selecting the scaled features, I want to convert this back to a dataframe of Doubles, though the length of my vectors are arbitrary. I know how to do it for a specific 3 features by using </p>
  
  <pre><code>myDF.map{case Row(v: Vector) =&gt; (v(0), v(1), v(2))}.toDF("f1", "f2", "f3")
  </code></pre>
  
  <p>but not for an arbitrary amount of features. Is there an easy way to do this?</p>
  
  <p>Example:</p>
  
  <pre><code>val testDF = sc.parallelize(List(Vectors.dense(5D, 6D, 7D), Vectors.dense(8D, 9D, 10D), Vectors.dense(11D, 12D, 13D))).map(Tuple1(_)).toDF("scaledFeatures")
  val myColumnNames = List("f1", "f2", "f3")
  // val finalDF = DataFrame[f1: Double, f2: Double, f3: Double] 
  </code></pre>
  
  <p>EDIT</p>
  
  <p>I found out how to unpack to column names when creating the dataframe, but still am having trouble converting a vector to a sequence needed to create the dataframe:</p>
  
  <pre><code>finalDF = testDF.map{case Row(v: Vector) =&gt; v.toArray.toSeq /* &lt;= this errors */}.toDF(List("f1", "f2", "f3"): _*)
  </code></pre>