You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by shilp <ts...@Hotmail.com> on 2016/10/17 14:37:51 UTC

Substitute Certain Rows a data Frame using SparkR

I have a sparkR Data frame and I want to Replace certain Rows of a Column
which satisfy certain condition with some value.If it was a simple R data
frame then I would do something as follows:df$Column1[df$Column1 == "Value"]
= "NewValue" How would i perform similar operation on a SparkR data frame.
??



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/Substitute-Certain-Rows-a-data-Frame-using-SparkR-tp27912.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

Re: Substitute Certain Rows a data Frame using SparkR

Posted by Felix Cheung <fe...@hotmail.com>.
It's a bit less concise but this works:

> a <- as.DataFrame(cars)
> head(a)
  speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10

> b <- withColumn(a, "speed", ifelse(a$speed > 15, a$speed, 3))
> head(b)
  speed dist
1 3 2
2 3 10
3 3 4
4 3 22
5 3 16
6 3 10

I think your example could be something we support though. Please feel free to open a JIRA for that.
_____________________________
From: shilp <ts...@hotmail.com>>
Sent: Monday, October 17, 2016 7:38 AM
Subject: Substitute Certain Rows a data Frame using SparkR
To: <us...@spark.apache.org>>


I have a sparkR Data frame and I want to Replace certain Rows of a Column which satisfy certain condition with some value.If it was a simple R data frame then I would do something as follows:df$Column1[df$Column1 == "Value"] = "NewValue" How would i perform similar operation on a SparkR data frame. ??
________________________________
View this message in context: Substitute Certain Rows a data Frame using SparkR<http://apache-spark-user-list.1001560.n3.nabble.com/Substitute-Certain-Rows-a-data-Frame-using-SparkR-tp27912.html>
Sent from the Apache Spark User List mailing list archive<http://apache-spark-user-list.1001560.n3.nabble.com/> at Nabble.com<http://Nabble.com>.