Skip to contents

stack() combines two price indexes with common levels, stacking index values and percent-change contributions for one index after the other.

unstack() breaks up a price index into a list of indexes for each time period.

These methods can be used in a map-reduce to make an index with multiple aggregation structures (like a Paasche index).

Usage

# S3 method for class 'chainable_piar_index'
stack(x, y, ...)

# S3 method for class 'direct_piar_index'
stack(x, y, ...)

# S3 method for class 'chainable_piar_index'
unstack(x, ...)

# S3 method for class 'direct_piar_index'
unstack(x, ...)

Arguments

x

A price index, as made by, e.g., elemental_index().

y

A price index, or something that can coerced into one. If x is a period-over-period index then y is coerced into a chainable index; otherwise, y is coerced into a direct index.

...

Not currently used.

Value

stack() returns a combined price index that inherits from the same class as x.

unstack() returns a list of price indexes with the same class as x.

Note

It may be necessary to use rebase() prior to stacking fixed-based price indexes to ensure they have the same base period.

Examples

index1 <- as_index(matrix(1:6, 2))

index2 <- index1
time(index2) <- 4:6

stack(index1, index2)
#> Period-over-period price index for 2 levels over 6 time periods 
#>   1 2 3 4 5 6
#> 1 1 3 5 1 3 5
#> 2 2 4 6 2 4 6

# Unstack does the reverse

all.equal(
  c(unstack(index1), unstack(index2)),
  unstack(stack(index1, index2))
)
#> [1] TRUE