Github user NarineK commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13760#discussion_r68116142
  
    --- Diff: R/pkg/R/group.R ---
    @@ -199,17 +199,10 @@ createMethods()
     #' Applies a R function to each group in the input GroupedData
     #'
     #' @param x a GroupedData
    -#' @param func A function to be applied to each group partition specified 
by GroupedData.
    -#'             The function `func` takes as argument a key - grouping 
columns and
    -#'             a data frame - a local R data.frame.
    -#'             The output of `func` is a local R data.frame.
    -#' @param schema The schema of the resulting SparkDataFrame after the 
function is applied.
    -#'               The schema must match to output of `func`. It has to be 
defined for each
    -#'               output column with preferred output column name and 
corresponding data type.
    -#' @return a SparkDataFrame
     #' @rdname gapply
     #' @name gapply
     #' @export
    +#' @seealso \link{gapplyCollect}
     #' @examples
     #' \dontrun{
    --- End diff --
    
    @shivaram, yes, the example for calculating the average is almost the same 
- in groups.R I use group_by and in DataFrame not but we could also combine all 
in let's say in DataFrame.R and so something like this:
    
    ```
    df <- createDataFrame (
    list(list(1L, 1, "1", 0.1), list(1L, 2, "1", 0.2), list(3L, 3, "3", 0.3)),
      c("a", "b", "c", "d"))
    
    Here our output contains three columns, the key which is a combination of 
two
    columns with data types integer and string and the mean which is a double.
    schema <-  structType(structField("a", "integer"), structField("c", 
"string"),
      structField("avg", "double"))
    df1 <- gapply(
      df,
      c("a", "c"),
      function(key, x) {
        y <- data.frame(key, mean(x$b), stringsAsFactors = FALSE)
      },
    schema)
    
    or we can also group the data and afterwards call gapply on GroupedData:
    gdf <- group_by(df, "a", "c")
    df1 <- gapply(
      gdf,
      function(key, x) {
        y <- data.frame(key, mean(x$b), stringsAsFactors = FALSE)
      },
    schema)
    collect(df1)
    ```
    Is this better ?


---
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]

Reply via email to