title: Expression 'id' is neither present in the group by, nor is it an aggregate function
body: <p>Using Scala and Spark 1.6.3, my error message is:</p>
  
  <pre class="lang-none prettyprint-override"><code>org.apache.spark.sql.AnalysisException: expression 'id' is neither present in the group by, nor is it an aggregate function. 
  Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
  </code></pre>
  
  <p>Code that generates error is:</p>
  
  <pre><code>returnDf.withColumn("colName", max(col("otherCol"))
  </code></pre>
  
  <p>The DataFrame returnDf looks like: </p>
  
  <pre class="lang-none prettyprint-override"><code>+---+--------------------+
  | id|            otherCol|
  +---+--------------------+
  |1.0|[0.0, 0.217764172...|
  |2.0|          [0.0, 0.0]|
  |3.0|[0.0, 0.142646382...|
  |4.0|[0.63245553203367...|
  </code></pre>
  
  <p>There is a solution to this when <a href="https://stackoverflow.com/questions/41421675/select-multiple-elements-with-group-by-in-spark-sql?rq=1">using sql syntax</a>. What is an equivalent solution using the syntax that I am using above (i.e. the <code>withColumn()</code> function)</p>