Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

I have a csv dataset that has date of births stored as characters in the format - 01-06-68("%d-%m-%y"). I tried to convert the dates to Date objects using as.Date() but it identifies the year as 2068 when in fact the year is 1968. I understand Date starts from 1970-01-01 in R, is there an easy fix to this?

I am using the lubridate package to find the age. Some age were negative due to the wrongly identified year.

elapsed <- train$Date.of.Birth %--% Sys.Date()

train$age <- floor(as.duration(elapsed) / dyears(1))

1 Answer

0 votes
by (41.4k points)

1.Here, you should use %y.

2.Then, create a new df with complete years .

Try this:

format(as.Date(date,format="%d-%m-%y"), "19%y-%m-%d")

Browse Categories