title: How to convert a DataFrame with String into a DataFrame with Vectors in Scala(Spark 2.0)
body: <p>I have a DataFrame with a column named <em>KFA</em> containing a string with angular braces on both ends. There are 4 double values in this long string. I would like to convert this into a DataFrame with vectors.</p>
  
  <p>This is the first element of the DataFrame:</p>
  
  <pre><code>&gt; dataFrame1.first()
  res130: org.apache.spark.sql.Row = [[.00663 .00197 .29809 .0034]]
  </code></pre>
  
  <p>Could you help me to covert it into a dense vector with 4 double values. </p>
  
  <p>I have tried this command</p>
  
  <pre><code>dataFrame1.select("KFA")
      .map((x=&gt;x.mkString("").replace("]","").replace("[","").split(" ")))
      .rdd.map(x=&gt;Vectors.dense(x(0).toDouble,x(1).toDouble,x(2).toDouble,x(3).toDouble,x(4).toDouble))
  </code></pre>
  
  <p>This looks very clumsy and unreadable. Could you suggest any other ways of doing this?</p>