I have an input dataframe with StartDate and EndDate, formatted as dates:
input_df:
C1 C2 StartDate EndDate
A B 9/5/2019 12/14/2019
C D 4/12/2019 5/14/2019
E F 12/5/2019 12/15/2019
I am trying to achieve the following output based on some conditions:
- If sys.date() is less than or equal to the EndDate, then I want to retain that row and add another row with Year+1
- If sys.Date() is greater than the EndDate, then replace 2019 from the year to 2020
The desired output is:
output_df:
C1 C2 StartDate EndDate
A B 9/5/2019 12/14/2019
A B 9/5/2020 12/14/2020
C D 4/12/2020 5/14/2020
E F 12/5/2019 12/15/2019
E F 12/5/2020 12/15/2020
I have explored separate_rows and lubridate but not sure how to incorporate an if condition with those functions. The dataframe is big and I am trying to avoid for loops to do this?