title: Dynamic column selection in Spark (based on another column's value)
body: <p>With the given Spark DataFrame:</p>
  
  <pre><code>&gt; df.show()
  
  +---+-----+---+---+---+---+
  | id|delay| p1| p2| p3| p4|
  +---+-----+---+---+---+---+
  |  1|    3|  a|  b|  c|  d|
  |  2|    1|  m|  n|  o|  p|
  |  3|    2|  q|  r|  s|  t|
  +---+-----+---+---+---+---+
  </code></pre>
  
  <p>How to select a column dynamically so that the new, <code>col</code> column is the result of the <code>p{delay}</code> existing column?</p>
  
  <pre><code>&gt; df.withColumn("col", /* ??? */).show()
  
  +---+-----+---+---+---+---+----+
  | id|delay| p1| p2| p3| p4| col|
  +---+-----+---+---+---+---+----+
  |  1|    3|  a|  b|  c|  d|   c|   // col = p3
  |  2|    1|  m|  n|  o|  p|   m|   // col = p1
  |  3|    2|  q|  r|  s|  t|   r|   // col = p2
  +---+-----+---+---+---+---+----+
  </code></pre>