Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/12836#discussion_r61708838
--- Diff: R/pkg/R/DataFrame.R ---
@@ -1187,6 +1187,65 @@ setMethod("dapply",
dataFrame(sdf)
})
+#' gapply
+#'
+#' Apply a function to each group of a DataFrame.
+#'
+#' @param x A SparkDataFrame
+#' @param func A function to be applied to each group partition specified
by grouping
+#' column of the SparkDataFrame.
+#' The output of func is a data.frame.
+#' @param schema The schema of the resulting DataFrame after the function
is applied.
+#' It must match the output of func.
+#' @family SparkDataFrame functions
+#' @rdname gapply
+#' @name gapply
+#' @export
+#' @examples
+#' \dontrun{
+#' df <- createDataFrame (sqlContext, iris)
+#' gdf <- gapply(df, function(x) { x }, schema(df), "Petal_Width")
+#' collect(gdf)
+#'
+#' Compute the square of the first columns and output it
+#'
+#' df <- createDataFrame (
+#' sqlContext,
+#' list(list(1L, 1, "1", 0.1), list(1L, 2, "2", 0.2), list(3L, 3, "3",
0.3)),
+#' c("a", "b", "c", "d"))
+#'
+#' schema <- structType(structField("result", "integer"))
+#' df1 <- gapply(
+#' df,
+#' function(x) {
+#' y <- x[1] * x[1]
+#' },
+#' schema, "a")
+#' collect(df1)
+#'
+#' result
+#' ------
+#' 1
+#' 1
+#' 9
--- End diff --
This example is not good for `flatMapGroups`.
---
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]