foldByKey {SparkR}R Documentation

Fold a pair RDD by each key.

Description

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.).

Usage

foldByKey(rdd, zeroValue, func, numPartitions)

## S4 method for signature 'RDD,ANY,ANY,integer'
foldByKey(rdd, zeroValue, func, numPartitions)

Arguments

rdd

An RDD.

zeroValue

A neutral "zero value".

func

An associative function for folding values of each key.

Value

An RDD containing the aggregation result.

See Also

aggregateByKey, combineByKey

Examples

## 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)

[Package SparkR version 0.1 Index]