调用reduceByKey时,它会使用相同的键对所有值求和.有没有办法计算每个键的平均值?
// I calculate the sum like this and don't know how to calculate the avg
reduceByKey((x,y)=>(x+y)).collect
Array(((Type1,1),4.0), ((Type1,1),9.2), ((Type1,2),8), ((Type1,2),4.5), ((Type1,3),3.5),
((Type1,3),5.0), ((Type2,1),4.6), ((Type2,1),4), ((Type2,1),10), ((Type2,1),4.3))
Run Code Online (Sandbox Code Playgroud) 我有一个带有大量数字的RDD(来自文件的行长度),我想知道如何通过数据获得单次传递的最小值/最大值.
我知道关于Min和Max函数,但这需要两次传递.