1

I am very new in R. So, I have some difficulties. I have a database in tibble (R language), where my first column is in character so i want to convert to date but I can't. I tried this code:

as.Date(x$Date, "%m-%y")

But doesn't work.

This is an example that follows

 <chr>
01-02
02-02
03-02
04-02
05-02
06-02
07-02
08-02

Do y'all have some tips to solve this little problem?

  • Does this answer your question? [Converting year and month ("yyyy-mm" format) to a date?](https://stackoverflow.com/questions/6242955/converting-year-and-month-yyyy-mm-format-to-a-date) – Dave2e Mar 30 '20 at 19:21

1 Answers1

0

For this, can easier option is as.yearmon

library(zoo)
as.Date(as.yearmon(x$Date, "%m-%y"))

Or paste with a day and then format

as.Date(paste0(x$Date, "-01"), "%m-%y-%d")
akrun
  • 874,273
  • 37
  • 540
  • 662