Reputation: 475
age.foreach(println)
1,5
2,25
3,30
Age has id and age. Now I have to create like If(age>=1 && age<10) "1-10" Else if(age >=10 && age<20) "10-20" Else "30+"
So the result for the above data should be
1, 1-10
2, 10-20
3, 30+
Val ager = age.map(x => (x(0),(If(x(1)>=1 && x(1)<10) "1- 10"
Else if(x(1) >=10 && x(1)<20) "10-20"
Else "30+")))
I am getting the below error: Error: org.apache.spark.rdd.RDD[(String,Int)] does not take parameter
Kindly help me to resolve this problem.
Upvotes: 2
Views: 5623
Reputation: 27373
tuple-elements are not access like x(0)
but x._1
etc
this should work:
val ager = age.map(x =>
(x._1, (if (x._2 >= 1 && x._2 < 10) "1- 10"
else if (x._2 >= 10 && x._2 < 20) "10-20"
else "30+"))
)
Upvotes: 2