I have a data frame of 1968 observations and am trying to parse the date column, where I have a string format into date format. Something like this:
df$date <- c("january 2020","january 2020","january 2020","february 2020","february 2020","february 2020","march 2020","march 2020","march 2020","april 2020","april 2020","april 2020","May 2020","May 2020","May 2020","june 2020","june 2020","june 2020")
I am using lubridate package:
date <- my(df$date)
Which bring’s a "857 failed to parse" warning and returns a vactor like this:
[1] NA NA NA NA NA NA 2020-03-01 2020-03-01 2020-03-01 NA NA NA NA NA NA 2020-06-01 2020-06-01 2020-06-01 2020-06-01
although I want the date in this format, ymd, I would like to have all observations parsed. I have also tried:
date <- as.Date(df$date)
date <- my(df$date, format = "%B %Y)
but these returns all observations as NA’s. What is happening?
thank you
>Solution :
as.Date(paste(1, df$date), '%d %B %Y')