title: How to calculate standard deviation and average values of RDD[Long]?
body: <p>I have <code>RDD[Long]</code> called <code>mod</code> and I want to compute standard deviation and mean values for this RDD using Spark 2.2 and Scala 2.11.8.</p>
  
  <p>How can I do it?</p>
  
  <p>I tried to calculate the average value as follows, but is there any easier way to get these values?</p>
  
  <pre><code>val avg_val = mod.toDF("col").agg(
      avg($"col").as("avg")
  ).first().toString().toDouble
  
  val stddev_val = mod.toDF("col").agg(
      stddev($"col").as("avg")
  ).first().toString().toDouble
  </code></pre>