0

I have date in character vector. I need to convert it to date format.

For example :

Month = "202005"

Output should be May-20. It should be in date format so that I can use to filter some dates. Similarly 201912 should return Dec-19

john
  • 1,026
  • 8
  • 19
  • Without the `zoo` package, you can try transforming `Month` into something that is acceptable by `as.Date`, for example `as.Date(paste(substring(Month,1,4), substring(Month,5), "01", sep = "-"))` – Felix Jassler Jul 03 '20 at 08:38

1 Answers1

1

zoo has a function called yearmon().

library(zoo)
month <- "202005"
as.yearmon(month, "%Y%m")
# "May 2020"
Nico
  • 463
  • 5
  • 11