title: Scala: Having a filter, selecting the values from another column
body: <p>First of all I'm using Scala on IntelliJ. Having this:</p>
  <pre><code>type     |  age
  electric |  30
  diesel   |  24
  gasoline |  28
  diesel   |  31
  </code></pre>
  <p>I would like to define a function that gets the average of the column &quot;age&quot;, excluding the type &quot;electric&quot;. I don't know how to filter one column and then operate in the other column maintaining the filter. For now, I've made this:</p>
  <pre><code>  def nonelectric (c: Seq[Df]): Double = {
      val cars = c.map(k =&gt; k.type)
      val nonelectriccars = cars.filterNot(cars=&gt; cars == &quot;electric&quot;)
      var a:Double = 0.0
      for (i &lt;- nonelectriccars){
        a += i
      }
      a/nonelectriccars.size.toDouble
    }
  </code></pre>
  <p>But, of course, I can't get the mean from the &quot;string&quot; type. How could I fix my code?</p>