title: Converting Scala mutable arrays to a spark dataframe
body: <p>I have three mutable arrays defined as:</p>
  
  <pre><code>import scala.collection.mutable.ArrayBuffer
  var quartile_1 = ArrayBuffer[Double]()
  var quartile_3 = ArrayBuffer[Double]()
  var id = ArrayBuffer[String]()
  </code></pre>
  
  <p>quartile_1 and quartile_3 are information at id level and I am currently computing them as:</p>
  
  <pre><code>def func1(x: org.apache.spark.sql.Row) {
    val apQuantile = df_auth_for_qnt.where($"id" === x(0).toString).stat.approxQuantile("tran_amt", Array(0.25, 0.75), 0.001)
    quartile_1 += apQuantile(0)
    quartile_3 += apQuantile(1)
    id += x(0).toString()
  }
  
  val cardNumList = df_auth_for_qnt_gb.where($"tran_cnt" &gt; 8).select("card_num_1").collect.foreach(func1)
  </code></pre>
  
  <p>Is there a better approach than appending them to mutable arrays? My goal is to have the quantile data, id available as a dataframe - so that I can do further joins. </p>