0

I've got a character like this:

"2008-11" and I want to convert it in a date format. (only year and month)

I've already tried with zoo package:

yearmon("2008-11") 

but it returns a NUM. I want a Date as structure. It should return 2008-11.

Which is the fastest way?

Thanks

fruit2day7
  • 71
  • 4

1 Answers1

1
library(anytime)

a <- anydate("2008-11")

> class(a)
[1] "Date"

> a
[1] "2008-11-01"
daniellga
  • 1,142
  • 6
  • 16
  • I don't want to have the day. How can I remove the day? Thanks! – fruit2day7 Aug 15 '20 at 13:30
  • If you want a Date class you must have the day. You can manipulate how the date is showed using format(), but then it will be converted back to character. https://stackoverflow.com/questions/61532807/r-how-to-remove-the-day-from-a-date – daniellga Aug 15 '20 at 13:36