Skip to contents

Construct period-over-period price relatives from information on prices and products over time.

Usage

price_relative(x, ...)

# Default S3 method
price_relative(x, ..., period, product)

# S3 method for class 'data.frame'
price_relative(x, formula, ...)

Arguments

x

Either a numeric vector (or something that can be coerced into one) or data frame of prices.

...

Further arguments passed to or used by methods.

period

A factor, or something that can be coerced into one, that gives the corresponding time period for each element in x. The ordering of time periods follows the levels of period to agree with cut().

product

A factor, or something that can be coerced into one, that gives the corresponding product identifier for each element in x.

formula

A two-sided formula with prices on the left-hand side, and time periods and products (in that order) on the right-hand side.

Value

A numeric vector of price relatives, with product as names.

See also

gpindex::back_period() to get only the back price.

gpindex::base_period() for making fixed-base price relatives.

carry_forward() and shadow_price() to impute missing prices.

gpindex::outliers for methods to identify outliers with price relatives.

Examples

price_relative(
  1:6,
  period = rep(1:2, each = 3),
  product = rep(letters[1:3], 2)
)
#>   a   b   c   a   b   c 
#> 1.0 1.0 1.0 4.0 2.5 2.0