mean

mean is an aggregate function that returns the average of all values in the specified column.

Syntax:

  • mean(df$col)

Parameters:

  • df: Any SparkR DataFrame
  • col: Column in SparkR DataFrame

Output:

  • Column Object
# Create SparkR DataFrame
df <- createDataFrame(sqlContext, mtcars)
head(df)
# Calculate average qsec (1/4 mile time)
head(select(df, mean(df$qsec)))