Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- result <-
- data %>%
- dplyr::select(!! cust_id, !! odate, !! revenues) %>%
- dplyr::group_by(!! cust_id) %>%
- dplyr::summarise(
- date_most_recent = max(!! odate), amount = sum(!! revenues),
- transaction_count = dplyr::n()
- ) %>%
- dplyr::mutate(
- recency_days = (analysis_date - date_most_recent) / lubridate::ddays()
- ) %>%
- dplyr::select(
- !! cust_id, date_most_recent, recency_days, transaction_count,
- amount
- ) %>%
- magrittr::set_names(c("customer_id", "date_most_recent", "recency_days", "transaction_count", "amount"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement