withColumnRenamedΒΆ

withColumnRenamed renames an existing column in a SparkDataFrame and returns a new SparkDataFrame.

Syntax:

  • withColumnRenamed(df, “existingColName”, “newColName”)

Parameters:

  • df: Any SparkDataFrame
  • existingColName: String, name of column in SparkDataFrame
  • newColName: String, new column name

Output:

  • SparkDataFrame
require(SparkR)

# Create SparkR DataFrame
df <- createDataFrame(mtcars)
head(df)
# Create a new df with column "mpg" renamed as "milesPerGallon"
newdf <- withColumnRenamed(df, "mpg", "milesPerGallon")
head(newdf)