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


R SparkR histogram用法及代碼示例

說明:

此函數計算給定 SparkR 列的直方圖。

用法:

## S4 method for signature 'SparkDataFrame,characterOrColumn'
histogram(df, col, nbins = 10)

參數:

  • df SparkDataFrame 包含要從中構建直方圖的 Column。
  • col 列作為字符串或用於構建直方圖的列。
  • nbins 箱子的數量(可選)。默認值為 10。

返回:

具有直方圖統計信息的 data.frame,即計數和質心。

注意:

自 2.0.0 以來的直方圖

例子:

# Create a SparkDataFrame from the Iris dataset
irisDF <- createDataFrame(iris)

# Compute histogram statistics
histStats <- histogram(irisDF, irisDF$Sepal_Length, nbins = 12)

# Once SparkR has computed the histogram statistics, the histogram can be
# rendered using the ggplot2 library:

require(ggplot2)
plot <- ggplot(histStats, aes(x = centroids, y = counts)) +
        geom_bar(stat = "identity") +
        xlab("Sepal_Length") + ylab("Frequency")

相關用法


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