I am working with a Feb 29 date in my dataset. I would like to change this date to Feb 28th when this occurs. I tried by using an ifelse statement to handle this situation, but the behavior is strange.
What I would like to accomplish is: if the month is 2, and the day of month is 29, then go back 1 day, else preserve the date.
When running:
library(lubridate)
dt<-ymd("2008-02-29")
dt<-ifelse(month(dt)==2 & day(dt)==29,
dt-days(1),dt)
dt
The above returns something very strange:
> dt
[1] 1204156800
However, when I run it without the ifelse statement the date math works just fine:
dt<-ymd("2008-02-29")
dt<-dt-days(1)
dt
> dt
[1] "2008-02-28 UTC"
Does anyone have any thoughts on how to accomplish this behavior? Thank you!