foldByKey {SparkR} | R Documentation |
Aggregate the values of each key in an RDD, using an associative function "func" and a neutral "zero value" which may be added to the result an arbitrary number of times, and must not change the result (e.g., 0 for addition, or 1 for multiplication.).
foldByKey(rdd, zeroValue, func, numPartitions) ## S4 method for signature 'RDD,ANY,ANY,integer' foldByKey(rdd, zeroValue, func, numPartitions)
rdd |
An RDD. |
zeroValue |
A neutral "zero value". |
func |
An associative function for folding values of each key. |
An RDD containing the aggregation result.
aggregateByKey, combineByKey
## Not run:
##D sc <- sparkR.init()
##D rdd <- parallelize(sc, list(list(1, 1), list(1, 2), list(2, 3), list(2, 4)))
##D foldByKey(rdd, 0, "+", 2L) # list(list(1, 3), list(2, 7))
## End(Not run)