add_group_sub_indices: Group a data frame and add in-group indices as a column.

View source: R/in_group_indices.R

add_group_sub_indicesR Documentation

Group a data frame and add in-group indices as a column.

Description

Group a data frame and add in-group indices as a column.

Usage

add_group_sub_indices(
  .data,
  ...,
  groupingVars,
  orderColumn,
  arrangeTerms = NULL,
  env = parent.frame()
)

Arguments

.data

data.frame

...

force later arguments to bind by name.

groupingVars

character vector of column names to group by.

orderColumn

character name of column to add in-group order marks to.

arrangeTerms

character vector of column expressions to arrange by.

env

environment to work in.

Value

.data with in group order indices added (no ties).

Examples



groupingVars = c("cyl", "gear")

datasets::mtcars %.>%
  # dplyr doesn't currently export tibble::rownames_to_column()
  mutate_se(., "CarName" := "rownames(.)" ) %.>%
  select_se(., c('CarName', 'cyl', 'gear', 'hp', 'wt')) %.>%
  add_group_indices(., groupingVars = groupingVars,
                    indexColumn = 'groupID') %.>%
  add_group_sub_indices(., groupingVars = groupingVars,
                       arrangeTerms = c('desc(hp)', 'wt'),
                       orderColumn = 'orderInGroup') %.>%
  arrange_se(., c('groupID', 'orderInGroup'))



WinVector/seplyr documentation built on Aug. 26, 2022, 12:01 p.m.