You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Nick Chammas <ni...@gmail.com> on 2014/07/10 21:53:37 UTC

How to RDD.take(middle 10 elements)

Interesting question on Stack Overflow:
http://stackoverflow.com/q/24677180/877069

Basically, is there a way to take() elements of an RDD at an arbitrary
index?

Nick
​




--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/How-to-RDD-take-middle-10-elements-tp9340.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

Re: How to RDD.take(middle 10 elements)

Posted by Xiangrui Meng <me...@gmail.com>.
This is expensive but doable:

rdd.zipWithIndex().filter { case (_, idx) => idx >= 10 && idx < 20 }.collect()

-Xiangrui

On Thu, Jul 10, 2014 at 12:53 PM, Nick Chammas
<ni...@gmail.com> wrote:
> Interesting question on Stack Overflow:
> http://stackoverflow.com/q/24677180/877069
>
> Basically, is there a way to take() elements of an RDD at an arbitrary
> index?
>
> Nick
>
>
> ________________________________
> View this message in context: How to RDD.take(middle 10 elements)
> Sent from the Apache Spark User List mailing list archive at Nabble.com.