0

Below is how my dataset looks:

S.No, Customer, Min Date, Max Date
1, Cus1 , 2015-04-01, 2018-12-01
2, Cus2 , 2015-01-01, 2017-11-01

For each customer I would like to create more date values between the min and max date.

Below is the expected output:

S.No, Customer, Min Date, Max Date , Date
1, Cus1 , 2015-04-01, 2018-12-01,2015-04-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-05-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-06-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-07-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-08-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-09-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-10-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-11-01
1, Cus1 , 2015-04-01, 2018-12-01,2015-12-01
1, Cus1 , 2015-04-01, 2018-12-01,2016-01-01
1, Cus1 , 2015-04-01, 2018-12-01,2016-02-01
1, Cus1 , 2015-04-01, 2018-12-01,2016-03-01
...........................................
...........................................
1, Cus1 , 2015-04-01, 2018-12-01,2018-01-12

Any leads would be highly appreciated.

Thanks.

MLavoie
  • 9,671
  • 41
  • 36
  • 56
Jay
  • 835
  • 1
  • 6
  • 11
  • Like this - https://stackoverflow.com/questions/16153920/transforming-a-min-and-a-max-value-into-a-range-of-values ? – thelatemail Mar 18 '19 at 05:25
  • My min and max dates are different for each customer, unlike for the link you have mentioned. However, let me try once.. Thanks! – Jay Mar 18 '19 at 05:37
  • From the dupe target link: `setDT(df)[, .(S.No = S.No, Customer = Customer, Min.Date = Min.Date, Max.Date = Max.Date, Date = seq(as.Date(Min.Date), as.Date(Max.Date), by = "month")), by = S.No]`; expanding by customer (or any other group) just means you need to add `by = S.No`; this is still a dupe post. – Maurits Evers Mar 18 '19 at 06:52
  • 1
    PS. I've noticed that you didn't accept a single answer to any of your previous questions. [Is there a particular reason for that?](https://stackoverflow.com/help/someone-answers) Please revisit those older posts and close the questions by setting the green check mark next to the solution that answers your question best. That way you keep SO tidy and help future SO readers/posters to identify relevant questions. – Maurits Evers Mar 18 '19 at 06:57

0 Answers0