groupingsets: Grouping sets

groupingsetsR Documentation

Grouping sets

Description

Functions for working with Grouping Sets, specifically as specified in the [Presto documentation](https://prestodb.io/docs/current/sql/select.html#group-by-clause).

Usage

gs_bool_to_group_number(x)

grouping_number(all_cols, included_cols)

grouping_parser(all_cols)

filter_grouping_set(
  .x,
  all_grouping_cols,
  group,
  .group_number_col = grouping_number
)

Arguments

x

a logical vector to convert into a grouping set number

all_cols

all of the grouping columns

included_cols

the group with the desired columns

.x

a data.frame-like object

all_grouping_cols

the columns included in the grouping sets

group

the columns included in the desired group

.group_number_col

the column containing the grouping number

Details

The grouping set number will correspond to the output of 'grouping' in Presto.

Value

a single number indicating the grouping set corresponding to the bool

the grouping number

a function that will parse grouping columns

the parsed data frame

Examples

gs_bool_to_group_number(c(TRUE, FALSE, FALSE))
grouping_number(
  c("origin_state", "origin_zip", "destination_state"),
  "origin_state"
)

colin-fraser/colinlib documentation built on Nov. 30, 2022, 11:10 p.m.