title: How to get a subset of columns based on row values in Spark Dataframe?
body: <p>I have the following dataframe in Spark (it has only one row):</p>
  
  <pre><code>df.show
  +---+---+---+---+---+---+
  |  A|  B|  C|  D|  E|  F|
  +---+---+---+---+---+---+
  |  1|4.4|  2|  3|  7|2.6|
  +---+---+---+---+---+---+
  </code></pre>
  
  <p>I want to get the columns that their values are greater than 2.8 (just as an example). The outcomes should be:</p>
  
  <pre><code>List(B, D , E)
  </code></pre>
  
  <p>Here is my own solution:</p>
  
  <pre><code>val cols = df.columns
  val threshold = 2.8
  val values = df.rdd.collect.toList
  val res = values
           .flatMap(x =&gt; x.toSeq)
           .map(x =&gt; x.toString.toDouble)
           .zip(cols)
           .filter(x =&gt; x._1 &gt; threshold)
           .map(x =&gt; x._2)
  </code></pre>