title: How to compose column name using another column's value for withColumn in Scala Spark
body: <p>I'm trying to add a new column to a <code>DataFrame</code>. The value of this column is the value of another column whose name depends on other columns from the same <code>DataFrame</code>.</p>
  
  <p>For instance, given this:</p>
  
  <pre class="lang-none prettyprint-override"><code>+---+---+----+----+
  |  A|  B| A_1| B_2|
  +---+---+----+----+
  |  A|  1| 0.1| 0.3|
  |  B|  2| 0.2| 0.4|
  +---+---+----+----+
  </code></pre>
  
  <p>I'd like to obtain this:</p>
  
  <pre class="lang-none prettyprint-override"><code>+---+---+----+----+----+
  |  A|  B| A_1| B_2|   C|
  +---+---+----+----+----+
  |  A|  1| 0.1| 0.3| 0.1|
  |  B|  2| 0.2| 0.4| 0.4|
  +---+---+----+----+----+
  </code></pre>
  
  <p>That is, I added column C whose value came from either column A_1 or B_2. The name of the source column A_1 comes from concatenating the value of columns A and B.</p>
  
  <p>I know that I can add a new column based on another and a constant like this:</p>
  
  <pre><code>df.withColumn("C", $"B" + 1)
  </code></pre>
  
  <p>I also know that the name of the column can come from a variable like this:</p>
  
  <pre><code>val name = "A_1"
  df.withColumn("C", col(name) + 1)
  </code></pre>
  
  <p>However, what I'd like to do is something like this:</p>
  
  <pre><code>df.withColumn("C", col(s"${col("A")}_${col("B")}"))
  </code></pre>
  
  <p>Which doesn't work.</p>
  
  <p>NOTE: I'm coding in Scala 2.11 and Spark 2.2.</p>