Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parse "january 2020" string to date format returns half of NA's in R

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading