group_index: Create Index Over Groupings

View source: R/S03_Utilities.R

group_indexR Documentation

Create Index Over Groupings

Description

Create a numeric index over the unique levels of a variable or a set of variables.

Usage

group_index(..., levels = NULL)

Arguments

...

Vectors of equal length.

levels

A list with the order of the unique levels for each input vector (indices assigned from first to last level).

Value

An integer vector from 1 to the number of unique levels.

Examples

# Convert to numeric index
group_index( rep( LETTERS[3:1], each = 3 ) )

# Can control assignment of indices
group_index(
  rep( LETTERS[3:1], each = 3 ), levels = list( c( 'C', 'B', 'A' ) )
)

# Can create single index over all
# unique combinations of multiple variables
group_index( rep( LETTERS[1:3], each = 3 ), rep( 1:3, 3 ) )


rettopnivek/arfpam documentation built on Oct. 20, 2024, 7:24 p.m.