alias

alias sets a new name for a column in a SparkR DataFrame. Typically used together with column operations.

If you need the entire DataFrame with only a certain column renamed, see withColumnRenamed.

Syntax:

  • alias(df$colName, “newColName”)

Parameters:

  • df: Any SparkR DataFrame
  • colName: Column in DataFrame
  • newColName: String, new column name

Output:

  • Column Object
# Create SparkR DataFrame
df <- createDataFrame(sqlContext, mtcars)
head(df)
# Select mpg column in df with new column name "milesPerGallon"
head(select(df, alias(df$mpg, "milesPerGallon")))
# alias() is usually used with column operations
head(select(df, alias(avg(df$mpg), "averageMPG")))