【发布时间】:2020-02-15 04:55:34
【问题描述】:
在下面的代码中,我根据以下代码生成了一个日期:
- 从具有一个或多个日期的字符串中获取第一个日期
- 将数值(提前期)添加到该日期以获得新日期
我现在要做的是使结果日期为每月 15 日或每月 1 日。这可以通过说“如果该月的日期为 15 日或更大,则将日期设为该月的 15 日,如果小于 15,则将日期设为该月的 1 日”)
我对 SQL 更熟悉,但不太清楚如何在 R 中使用最简单的方法来实现这一点
代码:
AAR_Combined_w_LL$newvalue <-mdy(substr(AAR_Combined_w_LL$order_cutoffs,0,10)) + AAR_Combined_w_LL$lead_time
样本数据:
season article_number order_cutoffs amount_of_limited_order_cut_offs retail_intro_date lead_time
1 adidas Fall/Winter 2020 GI7954 12/17/2019,01/14/2020,02/25/2020 3 2020-07-01 105
2 adidas Fall/Winter 2020 GI7955 12/17/2019,01/14/2020,02/25/2020 3 2020-07-01 105
3 adidas Fall/Winter 2020 P82146 12/17/2019 1 2020-06-01 75
4 adidas Fall/Winter 2020 S86676 12/17/2019 1 2020-06-01 75
5 adidas Fall/Winter 2020 P82145 12/17/2019 1 2020-06-01 75
6 adidas Fall/Winter 2020 S86673 12/17/2019 1 2020-06-01 75
1st_Booking_Deadline 1st_BW_Retail_Windows 2nd_Booking_Deadline 2nd_BW_Retail_Windows 3rd_Booking_Deadline 3rd_BW_Retail_Windows
1 2019-12-06 2020-07-01 - 2020-08-01 2020-01-24 2020-09-01 - 2020-11-01
2 2019-12-06 2020-07-01 - 2020-08-01 2020-01-24 2020-09-01 - 2020-11-01
3 2019-12-06 2020-06-01 - 2020-11-01
4 2019-12-06 2020-06-01 - 2020-11-01
5 2019-12-06 2020-06-01 - 2020-11-01
6 2019-12-06 2020-06-01 - 2020-11-01
4th_Booking_Deadline 4th_BW_Retail_Windows 5th_Booking_Deadline 5th_BW_Retail_Windows Booking_Deadlines Booking_Deadline_Intervals
1 2019-12-06, 2020-01-24, , , 2
2 2019-12-06, 2020-01-24, , , 2
3 2019-12-06, , , , NULL
4 2019-12-06, , , , NULL
5 2019-12-06, , , , NULL
6 2019-12-06, , , , NULL
newvalue
1 2020-03-31
2 2020-03-31
3 2020-03-01
4 2020-03-01
5 2020-03-01
6 2020-03-01
【问题讨论】: