I am calculating with dates in a For loop. I combine data from two dataframes. Tibble 1 contains variable A, tibble 2 contains variable B and C. A is a numerical variable, B and C are both dates.
I want to assign variable A a new variable if date B is within the interval of date C + 16 months.
I used the following:
if (B < C + months(16)) { Df1$A = A+1 }
For some dates this does not work. For example October 30th + 16 months = february 30th. The conditional expression fails as there is no true or falls and the for loop stops.
Is there a way to change C + months(16) to the last day of the month if the specific date (february 30th in the example above) does not exist?