Learn R Programming

seplyr (version 1.0.4)

add_group_sub_indices: 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

Run this code
# NOT RUN {

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'))


# }

Run the code above in your browser using DataLab