rank_sale: Filter sales to 1 row per customer per year.

Description Usage Arguments See Also Examples

View source: R/license-history.R

Description

Intended to run before make_history to ensure that multi-year/lifetime sales are accounted for. The default (and intended purpose) is to pick the maximum "duration" value per customer-year. Optionally, it will also pick the minimum value of month (intended for mid-year dashboards) if first_month = TRUE.

Usage

1
2
rank_sale(sale, rank_var = "duration", grp_var = c("cust_id", "year"),
  first_month = FALSE)

Arguments

sale

data frame: Input sales data

rank_var

character: name of variable(s) to use for ranking

grp_var

character: name of variable(s) used for grouping

first_month

logical: If TRUE, also ensures the output contains the earliest month by grp_var (intended for mid-year dashboards)

See Also

Salic Function Reference: salic

Other license history functions: history_check, make_history

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(dplyr)
data(lic, sale)

sale_unranked <- inner_join(lic, sale)
sale_ranked <- rank_sale(sale_unranked)
    
# check sale ranking - highest duration will always be picked
left_join(
    count(sale_ranked, duration), 
    distinct(sale_unranked, cust_id, year, duration) %>% count(duration), 
    by = "duration",
    suffix = c(".ranked", ".unranked")
)

# with earliest month included
sale_ranked <- rank_sale(sale_unranked, first_month = TRUE)
left_join(
    count(sale_ranked, month), 
    distinct(sale_unranked, cust_id, year, month) %>% count(month), 
    by = "month",
    suffix = c(".ranked", ".unranked")
)

southwick-associates/salic documentation built on Nov. 5, 2019, 9:13 a.m.