Reputation: 41
I have dates in the format 01jan2000 (without a space or any separator) and need to convert this to a date in R so I can calculate ages. I have tried both
mydata$censor_date <- as.Date(mydata$censor_date, "%d-%b-%Y")
and
mydata$censor_date <- as.Date(mydata$censor_date, "%d-%m-%Y")
But I only get NAs. I can do this in Excel, but would prefer to have one script to run rather than switch between programmes. The exact format of the date isn't important, as long as I can use R to calculate ages.
Thanks in Advance
Upvotes: 0
Views: 1214
Reputation: 7871
If you have date in "01jan2000" format you not need "-" in format.
Try
as.Date(mydata$censor_date, "%d%b%Y")
Upvotes: 1