0 votes
1 view
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 (38.2k 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")

Welcome to Intellipaat Community. Get your technical queries answered by top developers !