rs_unpair: Un-make sales pairs

Description Usage Arguments Details Value See Also Examples

View source: R/rsi.R

Description

Turn a wide dataset of sales pairs into a long data set with a single price and date variable.

Usage

1
2
3
4
5
6
7
8
rs_unpair(
  x,
  id = "id",
  date = "date",
  date_prev = "date_prev",
  price = "price",
  price_prev = "price_prev"
)

Arguments

x

A data.frame, or something that can be coerced into one.

id

Column name in x for a unique id.

date

Column name in x for a sales date.

date_prev

Column name in x for a previous sales date.

price

Column name in x for a sales price.

price_prev

Column name in x for a previous sales price.

Details

For each id, the previous price and date for the earliest sale are extracted, then concatenated (row-wise) back into x. Extra columns are expanded in the long format.

Un-making sales pairs is generally not well defined with missing and duplicated values, and these should be removed prior to un-making pairs.

Value

A data.frame.

See Also

rs_pair to perform the inverse operation.

Examples

1
2
3
4
5
6
7
8
9
# Turn into a 'wide' dataset of sales pairs
x <- data.frame(
id = c(1, 1, 2), 
date = c(2, 3, 3), 
date_prev = c(1, 2, 1), 
price = 3:1, 
price_prev = c(1, 3, 1)
)
rs_unpair(x)

marberts/ppd documentation built on March 27, 2020, 7:21 p.m.