Github user olarayej commented on a diff in the pull request:
https://github.com/apache/spark/pull/11569#discussion_r57342255
--- Diff: R/pkg/R/functions.R ---
@@ -2638,3 +2638,81 @@ setMethod("sort_array",
jc <- callJStatic("org.apache.spark.sql.functions",
"sort_array", x@jc, asc)
column(jc)
})
+
+#' This function computes a histogram for a given SparkR Column.
+#'
+#' @name histogram
+#' @title Histogram
+#' @param nbins the number of bins (optional). The default is 10.
+#' @param df the DataFrame containing the Column to build the histogram
from.
+#' @param colname the name of the column to build the histogram from.
+#' @return a data.frame with the histogram statistics, i.e., counts and
centroids.
+#' @examples \dontrun{
+#'
+#' # Create a DataFrame from the Iris dataset
+#' irisDF <- createDataFrame(sqlContext, iris)
+#'
+#' # Compute histogram statistics
+#' histData <- histogram(df, "colname"Sepal_Length", nbins = 12)
+#'
+#' # Once SparkR has computed the histogram statistics, it would be very
easy to
+#' # render the histogram using R's visualization packages such as ggplot2.
+#'
+#' }
+setMethod("histogram",
+ signature(df = "DataFrame"),
+ function(df, colname, nbins = 10) {
+ # Validate nbins
+ if (nbins < 2) {
+ stop("The number of bins must be a positive integer number
greater than 1.")
--- End diff --
R doesn't (see below). Let me change my code so it rounds nbins to the
lowest integer.
> str(hist(iris$Sepal.Length, breaks=10.5))
List of 6
$ breaks : num [1:9] 4 4.5 5 5.5 6 6.5 7 7.5 8
$ counts : int [1:8] 5 27 27 30 31 18 6 6
$ density : num [1:8] 0.0667 0.36 0.36 0.4 0.4133 ...
$ mids : num [1:8] 4.25 4.75 5.25 5.75 6.25 6.75 7.25 7.75
$ xname : chr "iris$Sepal.Length"
$ equidist: logi TRUE
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]