rs_pair: Make sales pairs

Description Usage Arguments Details Value See Also Examples

View source: R/rsi.R

Description

Turn a long dataset with repeat sales information into a dataset of sales pairs.

Usage

1
rs_pair(x, id = "id", date = "date", price = "price")

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.

price

Column name in x for a sales price.

Details

Consecutive sales for each id are turned into pairs of consecutive sales. This is equivalent to first-differencing the data.

Observations with missing values and duplicated observations are not removed prior to creating sales pairs. Making sales pairs is generally not well defined with missing and duplicated values, and these should be removed prior to making pairs.

Extra columns with data that does not varying over time for each id are preserved when making pairs.

Value

A data.frame.

See Also

rs_unpair to perform the inverse operation.

Examples

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

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