Search code examples
scalaapache-sparksubtraction

How to subtract two doubles?


I want to get IRQ in Spark. How can I subtract two values (double or int)?

I tried the code below but only got error:

scala> Q1
res103: org.apache.spark.sql.Row = [11.09314]
scala> Q3
res104: org.apache.spark.sql.Row = [34.370419]
scala> val IRQ = Math.abs(Q3-Q1)
<console>:43: error: value - is not a member of org.apache.spark.sql.Row
       val IRQ = Math.abs(Q3-Q1)

Solution

  • This should do the trick:

    val IQR = Math.abs(Q3.getDouble(0) - Q1.getDouble(0))
    

    See the docs for Row interface here.