2

I am trying to parse a date with 2 digit years. However this does not work. Can somebody please tell me why?

Browse[1]> as.Date("Jan-84", format = "%b-%y")
[1] NA
user1434997
  • 1,689
  • 2
  • 12
  • 12

1 Answers1

8

The zoo package is helpful for this:

require(zoo)

x <- as.yearmon("Jan-84", format = "%b-%y")

The lines above first convert the input to class yearmon:

"Jan 1984"

From there you can convert the yearmon class to Date (or POSIXct), like this:

x <– as.Date(x)

Now the object is of class Date:

"1984-01-01"
www
  • 4,124
  • 1
  • 11
  • 22