title: Unable to convert an rdd with zipWithIndex to a dataframe in spark
body: <p>I am unable to convert an rdd with <code>zipWithIndex</code> to a dataframe.</p>
  
  <p>I have read from a file and I need to skip the first 3 records and then limit the records to row number 10. For this, I used <code>rdd.zipwithindex</code>.</p>
  
  <p>But afterwards, when I try to save the 7 records , I am not able to do so.</p>
  
  <pre><code>val df = spark.read.format("com.databricks.spark.csv")
                     .option("delimiter", delimValue)
                     .option("header", "false")
                     .load("/user/ashwin/data1/datafile.txt")
  
  val df1 = df.rdd.zipWithIndex()
                  .filter(x =&gt; { x._2 &gt; 3&amp;&amp; x._2 &lt;= 10;})
                  .map(f =&gt; Row(f._1))
  
  val skipValue = 3
  
  val limitValue = 10
  
  val delimValue = ","
  
  df1.foreach(f2=&gt; print(f2.toString))
  [[113,3Bapi,Ghosh,86589579]][[114,4Bapi,Ghosh,86589579]]
  [[115,5Bapi,Ghosh,86589579]][[116,6Bapi,Ghosh,86589579]]
  [[117,7Bapi,Ghosh,86589579]][[118,8Bapi,Ghosh,86589579]]
  [[119,9Bapi,Ghosh,86589579]]
  
  
  
  scala&gt; val df = spark.read.format("com.databricks.spark.csv").option("delimiter", delimValue).option("header", "true").load("/user/bigframe/ashwin/data1/datafile.txt")
  df: org.apache.spark.sql.DataFrame = [empid: string, fname: string ... 2 more fields]
  
  scala&gt; val df1 = df.rdd.zipWithIndex().filter(x =&gt; { x._2 &gt; skipValue &amp;&amp; x._2 &lt;= limitValue;}).map(f =&gt; Row(f._1))
  df1: org.apache.spark.rdd.RDD[org.apache.spark.sql.Row] = MapPartitionsRDD[885] at map at &lt;console&gt;:38
  
  scala&gt; import spark.implicits._
  import spark.implicits._
  </code></pre>
  
  <p>scala> df1.</p>
  
  <pre><code>    ++             count                 flatMap                 groupBy           mapPartitionsWithIndex   reduce             takeAsync         union
  aggregate      countApprox           fold                    id                max                      repartition        takeOrdered       unpersist
  cache          countApproxDistinct   foreach                 intersection      min                      sample             takeSample        zip
  cartesian      countAsync            foreachAsync            isCheckpointed    name                     saveAsObjectFile   toDebugString     zipPartitions
  checkpoint     countByValue          foreachPartition        isEmpty           partitioner              saveAsTextFile     toJavaRDD         zipWithIndex
  coalesce       countByValueApprox    foreachPartitionAsync   iterator          partitions               setName            toLocalIterator   zipWithUniqueId
  collect        dependencies          getCheckpointFile       keyBy             persist                  sortBy             toString
  collectAsync   distinct              getNumPartitions        localCheckpoint   pipe                     sparkContext       top
  compute        filter                getStorageLevel         map               preferredLocations       subtract           treeAggregate
  context        first                 glom                    mapPartitions     randomSplit              take               treeReduce
  
  scala&gt; df1.toDF
  &lt;console&gt;:44: error: value toDF is not a member of org.apache.spark.rdd.RDD[org.apache.spark.sql.Row]
         df1.toDF
         ^
  </code></pre>