title: Spark - Sort Double values in an RDD and ignore NaNs
body: <p>I want to sort the Double values in a RDD and I want my sort function to ignore the Double.NaN values. </p>
  
  <p>Either the Double.NaN values should appear at the bottom or top of the sorted RDD.</p>
  
  <p>I was not able to achieve this using sortBy.</p>
  
  <pre><code>scala&gt; res13.sortBy(r =&gt; r, ascending = true)
  res21: org.apache.spark.rdd.RDD[Double] = MapPartitionsRDD[10] at sortBy at &lt;console&gt;:26
  
  scala&gt; res21.collect.foreach(println)
  0.656
  0.99
  0.998
  1.0
  NaN
  5.6
  7.0
  
  scala&gt; res13.sortBy(r =&gt; r, ascending = false)
  res23: org.apache.spark.rdd.RDD[Double] = MapPartitionsRDD[15] at sortBy at &lt;console&gt;:26
  
  scala&gt; res23.collect.foreach(println)
  7.0
  5.6
  NaN
  1.0
  0.998
  0.99
  0.656
  </code></pre>
  
  <p>My expected result is </p>
  
  <pre><code>scala&gt; res23.collect.foreach(println)
      7.0
      5.6
      1.0
      0.998
      0.99
      0.656
      NaN
  
  or 
      scala&gt; res21.collect.foreach(println)
      NaN
      0.656
      0.99
      0.998
      1.0
      5.6
      7.0
  </code></pre>