Question: I have a df with a date column (year month) like this: 7-Feb, 7-March ( meaning February 2007, March 2007 etc). I want to make it like this 2007-02, 2007-03 etc. I tried to solve it by this code

```
as.Date(df$date,format="%y-%b")

```

But it produces na na ...

As a new learner of r, could you help me in this regard?

Answer: 
You can use `zoo::as.yearmon` function as:

```
library(zoo)

as.yearmon("7-Feb", "%y-%b")
#[1] "Feb 2007"

format(as.yearmon("7-Feb", "%y-%b"),"%m-%Y")
#[1] "02-2007"

#For OP's data.frame:

df$date <- as.yearmon(df$date, "%y-%b")

```
The easiest way is to a add a day to your string like in this example:

```
as.Date(paste0("01-", "7-Feb"), "%d-%y-%b")

```

Here I am setting the date to the first of the month. In your case one can replace "7-Feb" with your vector of strings.