我试图在scala中减去两列RDD3tuples。然而,当我试图在代码中减去r-a时,我得到了这个错误:
overloaded method value - with alternatives:
[error] (x: Double)Double <and>
[error] (x: Float)Double <and>
[error] (x: Long)Double <and>
[error] (x: Int)Double <and>
[error] (x: Char)Double <and>
[error] (x: Short)Double <and>
[error] (x: Byte)Double
[error] cannot be applied to (AnyVal)
[error] val newnom = userRatings.leftOuterJoin(newUserAverages).map { case (u, (r, a)) => (u, r - a.getOrElse())}
代码:
val userRatings = train.map(x => (x._1, x._3))
val userAverages = userRatings.groupBy(_._1).mapValues(_.map(_._2)).map{case (u, r) => (u, (r.sum/r.size).toDouble)}
val newnom = userRatings.leftOuterJoin(userAverages).map { case (u, (r, a)) => (u, r - a.getOrElse())}
rdd元组在应用map之前是这样的(为什么我在.3元素上使用.getorelse):
(451,(1.0,Some(2.7362637362637363)))
(451,(4.0,Some(2.7362637362637363)))
(451,(2.0,Some(2.7362637362637363)))
(451,(4.0,Some(2.7362637362637363)))
(451,(4.0,Some(2.7362637362637363)))
我基本上希望最后一个值从第二个值中减去,我希望从文本中可以清楚地看到。试图用多种方式转换数字,舍入,格式化等。。但还是会有同样的错误。
1条答案
按热度按时间k7fdbhmy1#
解决了。用作[number].doublevalue的示例,可能适用于类似的重载错误。