Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. result <-
  2. data %>%
  3. dplyr::select(!! cust_id, !! odate, !! revenues) %>%
  4. dplyr::group_by(!! cust_id) %>%
  5. dplyr::summarise(
  6. date_most_recent = max(!! odate), amount = sum(!! revenues),
  7. transaction_count = dplyr::n()
  8. ) %>%
  9. dplyr::mutate(
  10. recency_days = (analysis_date - date_most_recent) / lubridate::ddays()
  11. ) %>%
  12. dplyr::select(
  13. !! cust_id, date_most_recent, recency_days, transaction_count,
  14. amount
  15. ) %>%
  16. magrittr::set_names(c("customer_id", "date_most_recent", "recency_days", "transaction_count", "amount"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement