Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the year in a datetime object in R?

Tags:

date

r

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.

like image 241
goldisfine Avatar asked Dec 04 '14 05:12

goldisfine


1 Answers

> 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"
like image 150
Gregor Thomas Avatar answered Sep 23 '22 05:09

Gregor Thomas