Learn R Programming

SparkR (version 2.1.2)

histogram: Compute histogram statistics for given column

Description

This function computes a histogram for a given SparkR Column.

Usage

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

Arguments

df

the SparkDataFrame containing the Column to build the histogram from.

col

the column as Character string or a Column to build the histogram from.

nbins

the number of bins (optional). Default value is 10.

Value

a data.frame with the histogram statistics, i.e., counts and centroids.

See Also

Other SparkDataFrame functions: SparkDataFrame-class, agg, arrange, as.data.frame, attach, cache, coalesce, collect, colnames, coltypes, createOrReplaceTempView, crossJoin, dapplyCollect, dapply, describe, dim, distinct, dropDuplicates, dropna, drop, dtypes, except, explain, filter, first, gapplyCollect, gapply, getNumPartitions, group_by, head, insertInto, intersect, isLocal, join, limit, merge, mutate, ncol, nrow, persist, printSchema, randomSplit, rbind, registerTempTable, rename, repartition, sample, saveAsTable, schema, selectExpr, select, showDF, show, storageLevel, str, subset, take, union, unpersist, withColumn, with, write.df, write.jdbc, write.json, write.orc, write.parquet, write.text

Examples

Run this code
# NOT RUN {
# 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")
# }

Run the code above in your browser using DataLab