1

This works as expected:

> as.Date("07/01/08","%m/%d/%y")
[1] "2008-07-01"

But not this:

> as.Date("07/08","%m/%y")
[1] NA

Bonus question, explain this:

> as.Date("08","%y")
[1] "2008-09-08"

UPDATE

OK, so I guess I can get something reasonable with this?

my.date = "07/08"
as.Date(paste0("01/",my.date),"%m/%d/%y")

Anything simpler? I've got a column of month/years I'd like to convert to Date objects:

my.dates = c("07/08","08/08","09/08","10/08")
as.Date(paste0("01/",my.dates),"%m/%d/%y")
stackoverflax
  • 1,077
  • 3
  • 11
  • 25
  • Looks like your third example `as.Date("08","%y")` uses the current date and changes the year. It appears that such default behavior was not designed with your second example `as.Date("07/08","%m/%y")`. – Blue Magister Sep 09 '13 at 02:09
  • This might be of interest: http://stackoverflow.com/questions/7480499/unable-to-format-months-with-as-date – thelatemail Sep 09 '13 at 02:14
  • See `?yearmon` from the `zoo` package to do what you want with month/year data. – thelatemail Sep 09 '13 at 02:19

0 Answers0