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.

Description

Return a new RDD by applying a function to each partition of this RDD, while tracking the index of the original partition.

Usage

lapplyPartitionsWithIndex(X, FUN)

## S4 method for signature 'RDD,'function''
lapplyPartitionsWithIndex(X, FUN)

mapPartitionsWithIndex(X, FUN)

## S4 method for signature 'RDD,'function''
mapPartitionsWithIndex(X, FUN)

Arguments

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.

Value

a new RDD created by the transformation.

Examples

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

[Package SparkR version 0.1 Index]