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

Description Usage Arguments Value Examples

View source: R/in_group_indices.R

Description

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

Usage

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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'))

seplyr documentation built on Sept. 5, 2021, 5:12 p.m.