Sebastian Zeki Sebastian Zeki - 9 months ago 52
R Question

as.Date keeps on returning NAs

So I've been through the stack exchange answers and I can't resolve this

I have a column in a dataframe that has dates as characters as follows



I would like to convert these to date formats which I have tried to do as follows:


but I get NA's back all the time

I tried to do as here but no joy. I'm really not sure what Im doing wrong.

Answer Source

I'd say as.Date won't be able to work on values where there's no day of the month. You could try with zoo, as long as you don't mind it coming out as a yearmon class:

library( zoo )
as.yearmon( Tots$DatesMerge )

Alternatively, you can specify a day of the month to use as a dummy:

as.Date( paste0( Tots$DatesMerge, "-15" ) )