title: Evaluating multiple filters in a single pass
body: <p>I have below rdd created and I need to perform a series of filters on the same dataset to derive different counters and aggregates.</p>
  
  <p>Is there a way I can apply these filters and compute aggregates in a single pass, avoiding spark to go over the same dataset multiple times?</p>
  
  <pre><code>val res = df.rdd.map(row =&gt; {
      // ............... Generate data here for each row.......
  })
  
  res.persist(StorageLevel.MEMORY_AND_DISK)
  val all = res.count()
  
  val stats1 = res.filter(row =&gt; row.getInt(1) &gt; 0)
  val stats1Count = stats1.count()
  val stats1Agg = stats1.map(r =&gt; r.getInt(1)).mean()
  
  val stats2 = res.filter(row =&gt; row.getInt(2) &gt; 0)
  val stats2Count = stats2.count()
  val stats2Agg = stats2.map(r =&gt; r.getInt(2)).mean()
  </code></pre>