selectExprΒΆ

selectExpr is a variant of select that selects columns in a SparkDataFrame while projecting SQL expressions.

Syntax:

  • selectExpr(DataFrame, expr, ...)

Parameters:

  • DataFrame: Any SparkR DataFrame
  • expr: String. SQL Expression

Output:

  • SparkR DataFrame
require(SparkR)

# Create SparkR DataFrame
df <- createDataFrame(airquality)
head(df)
# You can select multiple columns
head(selectExpr(df, "Day", "Day + 99", "Day * 3"))
# You can also rename selected columns
head(selectExpr(df, "(max(Temp) - min(Temp)) as TempDiff"))