pivot {SparkR}R Documentation

Pivot a column of the GroupedData and perform the specified aggregation.

Description

Pivot a column of the GroupedData and perform the specified aggregation. There are two versions of pivot function: one that requires the caller to specify the list of distinct values to pivot on, and one that does not. The latter is more concise but less efficient, because Spark needs to first compute the list of distinct values internally.

Usage

## S4 method for signature 'GroupedData,character'
pivot(x, colname, values = list())

Arguments

x

a GroupedData object

colname

A column name

values

A value or a list/vector of distinct values for the output columns.

Value

GroupedData object

Note

pivot since 2.0.0

Examples

## Not run: 
##D df <- createDataFrame(data.frame(
##D     earnings = c(10000, 10000, 11000, 15000, 12000, 20000, 21000, 22000),
##D     course = c("R", "Python", "R", "Python", "R", "Python", "R", "Python"),
##D     period = c("1H", "1H", "2H", "2H", "1H", "1H", "2H", "2H"),
##D     year = c(2015, 2015, 2015, 2015, 2016, 2016, 2016, 2016)
##D ))
##D group_sum <- sum(pivot(groupBy(df, "year"), "course"), "earnings")
##D group_min <- min(pivot(groupBy(df, "year"), "course", "R"), "earnings")
##D group_max <- max(pivot(groupBy(df, "year"), "course", c("Python", "R")), "earnings")
##D group_mean <- mean(pivot(groupBy(df, "year"), "course", list("Python", "R")), "earnings")
## End(Not run)

[Package SparkR version 2.4.5 Index]