title: spark - Calculating average of values in 2 or more columns and putting in new column in every row
body: <p>Suppose I have a Dataset/Dataframe with following contents:-</p>
  
  <pre><code>name, marks1, marks2
  Alice, 10, 20
  Bob, 20, 30
  </code></pre>
  
  <p>I want to add a new column which should have the average of column B and C.</p>
  
  <p>Expected Result:-</p>
  
  <pre><code>name, marks1, marks2, Result(Avg)
  Alice, 10, 20, 15
  Bob, 20, 30, 25
  </code></pre>
  
  <p>for Summing or any other arithmetic operation I use <code>df.withColumn("xyz", $"marks1"+$"marks2")</code>. I cannot find a similar way for Average. Please help.</p>
  
  <p>Additionally:- The number of columns are not fixed. Like sometimes it might be average of 2 columns, sometimes 3 or even more. So I want a generic code which should work. </p>