Pauline Pauline - 4 months ago 8
R Question

how can i modify dmy() in lubridate function to output the 1900s instead of the 2000s?

I have data that only show the last two digits of a year. Using

dmy("090965")

the output is "2065-09-09".
I would like it to be "1965-09-09". How do I modify this to get the output?

Answer

One way of doing things:

a=dmy("090965") 
year(a)=1965  

# or if you have a vector with multiple years: 
year(a)=year(a)-100

> a
[1] "1965-09-09"