Change the year in a datetime object in R?

date, r

Solution

> x <- as.Date('0014-06-30')
> x
[1] "0014-06-30"
> library(lubridate)
> year(x)
[1] 14
> year(x) <- 0
> x
[1] "0000-06-30"

Problem

I have the following: ``` "0014-06-30" ``` And I'd like to change it to: ``` "0000-06-30" ``` How would I do this in R? Everything that I'm reading is very focused on converting strings to dates rather than changing around the elements inside a date.

Original source