I am trying to create a new variable that is based on customer_id and dates. The table is a log of all customer contact, so there will be duplicate customer IDs. What I want to do it create a new variable that has a sequential count by using dates of contact within x days for each customer. All first contact from a customer will be = 1 and if there is a gap greater than x days since last contact, then that contact will be 2 and so on and so forth. I am trying to create the "Journey" variable.
Thanks for any guidance.
here is the code:
structure(list(Customer = structure(c(1L, 1L, 2L, 3L, 3L, 3L,
4L, 4L, 4L, 4L), .Label = c("A", "B", "C", "D"), class = "factor"),
Start_dt = c("2018-04-30 13:47:13", "2018-05-03 09:22:25",
"2018-04-22 10:45:33", "2018-04-20 09:55:51", "2018-04-21 14:20:33",
"2018-05-01 15:27:43", "2018-03-28 11:25:45", "2018-04-28 10:30:35",
"2018-05-17 11:08:51", "2018-06-02 10:38:38"), End_dt = c("2018-04-30 14:22:15",
"2018-05-03 10:05:32", "2018-04-22 11:00:35", "2018-04-20 09:57:45",
"2018-04-21 14:27:14", "2018-05-01 16:03:25", "2018-03-28 11:35:54",
"2018-04-28 11:02:17", "2018-05-17 12:32:18", "2018-06-02 11:08:29"
), Journey = c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 4L)), class = "data.frame", row.names = c(NA,
-10L))