If I have a RDD that looks like:
var rdd = Array(4, 5, 7, 8, 9, 5, 3, 2, 1, 2, 13, 12, .....)
How do I select those elements which are located at equal distances, say, every third element, such that,
var rdd1 = Array(4, 8, 3, 2, ...)
var rdd2 = Array(5, 9, 2, 13, ..)
var rdd3 = Array(7, 5, 1, 12, ..)
What I have tried is, using zipWithIndex and then computing if index % 3 = 0/1/2.
var rdd1/2/3 = rdd.zipWithIndex.filter(case (val, index) => index%3 ==0/1/2)
(Pardon the exact syntax)
The approach works but is very inefficient for large Rdds. What are some other ways you would do this Scala? Thank you. Your help is very appreciated.