I have an R data frame and one of its column is a date column in the YYYY-MM-DD format.
Assuming my data frame is called df1 and the date column is called ref.date, how can I create a new column (to be called Category) based on the following logic:
If **ref.date** between `2018-04-01` and `2019-04-01` then **Yr1**
If **ref.date** between `2019-04-01` and `2020-04-01` then **Yr2**
If **ref.date** between `2020-04-01` and `2021-04-01` then **Yr3**
Else **Not Stated**
Any help would be much appreciated.
Note: I had a look at the answers provided in this StackOverflow question but I can't wrap my head around how to implement one of them for my problem: