Convert month month to date in r

I need to convert the following string types to date format.

Convert "Feb 2009" to 2009-02-01
Convert "Jan 2010" to 2010-01-01
Convert "Mar 2011" to 2011-03-01

      

I can achieve this from the following code using a package zoo

.

as.Date(as.yearmon("Feb 2009"))

      

But due to some limitations, I don't want to use this conversion method. So, I want to know if there is another way in R to accomplish this task?

+3


source to share


1 answer


You can insert 01

into a vector using paste

and then convert to date

by specifying the appropriateformat

as.Date(paste('01', v1), format='%d %b %Y')
#[1] "2009-02-01" "2010-01-01", "2011-03-01"

      



data

v1 <- c("Feb 2009", "Jan 2010", "Mar 2011")

      

+9


source







All Articles