當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R SparkR groupBy用法及代碼示例

說明:

使用指定的列對 SparkDataFrame 進行分組,因此我們可以在它們上運行聚合。

用法:

group_by(x, ...)

groupBy(x, ...)

## S4 method for signature 'SparkDataFrame'
groupBy(x, ...)

## S4 method for signature 'SparkDataFrame'
group_by(x, ...)

參數:

  • x 一個 SparkDataFrame。
  • ... 要分組的字符名稱或列。

返回:

分組數據。

注意:

groupBy 自 1.4.0 起

group_by 從 1.4.0 開始

例子:

# Compute the average for all numeric columns grouped by department.
  avg(groupBy(df, "department"))

  # Compute the max age and average salary, grouped by department and gender.
  agg(groupBy(df, "department", "gender"), salary="avg", "age" -> "max")

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 GroupBy。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。