lapplyPartitionsWithIndex {SparkR} | R Documentation |
Return a new RDD by applying a function to each partition of this RDD, while tracking the index of the original partition.
lapplyPartitionsWithIndex(X, FUN) ## S4 method for signature 'RDD,'function'' lapplyPartitionsWithIndex(X, FUN) mapPartitionsWithIndex(X, FUN) ## S4 method for signature 'RDD,'function'' mapPartitionsWithIndex(X, FUN)
X |
The RDD to apply the transformation. |
FUN |
the transformation to apply on each partition; takes the partition index and a list of elements in the particular partition. |
a new RDD created by the transformation.
## Not run:
##D sc <- sparkR.init()
##D rdd <- parallelize(sc, 1:10, 5L)
##D prod <- lapplyPartitionsWithIndex(rdd, function(split, part) {
##D split * Reduce("+", part) })
##D collect(prod, flatten = FALSE) # 0, 7, 22, 45, 76
## End(Not run)