title: Compute average of numbers in a text file in spark scala
body: <p>Lets say I have a file with each line representing a number. How do I find average of all the numbers in the file in Scala - Spark.</p>
  
  <pre><code>val data = sc.textFile("../../numbers.txt")
  val sum = data.reduce( (x,y) =&gt; x+y )
  val avg = sum/data.count()
  </code></pre>
  
  <p>The problem here is x and y are strings. How do I convert them into Long within the reduce function. </p>