title: How to do conditional "withColumn" in a Spark dataframe?
body: <p>I have a dataframe (mydf) as follows:</p>
  
  <pre><code>+---+---+---+---+
  | F1| F2| F3| F4|
  +---+---+---+---+
  |  t| y4|  5|1.0|
  |  x|  y|  1|0.5|
  |  x|  y|  1|0.5|
  |  x|  z|  2|1.0|
  |  x|  b|  5|1.0|
  |  t| y2|  6|1.0|
  |  t| y3|  3|1.0|
  |  x|  a|  4|1.0|
  +---+---+---+---+
  </code></pre>
  
  <p>I want to do a conditional aggregation inside "<code>withColumn</code>" as follows:</p>
  
  <pre><code>mydf.withColumn("myVar", if($"F3" &gt; 3) sum($"F4") else 0.0)
  </code></pre>
  
  <p>that is for every row having <code>$F3 &lt;= 0</code> , <code>myVar</code> should have a value of 0.0 and others sum of <code>$"F4"</code>.</p>
  
  <p>How to achieve it in Spark Scala?</p>