0

My data looks like this:

head(fsd$year)

[1] Jan-1965 Feb-1965 Mar-1965 Apr-1965 May-1965 Jun-1965
607 Levels: Apr-1965 Apr-1966 Apr-1967 Apr-1968 Apr-1969 Apr-1970 ... Sep-2014

I want to convert this into Date format.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Mac
  • 111
  • 1
  • 2
  • 10
  • One way `as.Date(paste0("01-", fsd$year), "%d-%b-%Y")` or with `zoo` library `as.yearmon( fsd$year, "%b-%Y")` – Ronak Shah Jan 06 '17 at 02:22
  • Side-question: why doesn't `lubridate::parse_date_time(x, "%b!-%Y!")` work here? `%b!` is for abbreviated month, `%Y!` for year with century, so… ? – Fr. Jan 06 '17 at 02:44
  • Even `lubridate::parse_date_time(x, "b Y")` should work here, but doesn't. Is `lubridate` limited to full "dmy" parsing? – Fr. Jan 06 '17 at 02:45
  • 1
    @Fr. - a month/year combo isn't a complete date according to R's date parsing. Interestingly enough, a `d/m` combo just gets assigned to the current year. – thelatemail Jan 06 '17 at 03:25
  • @thelatemail Thanks, I did not know either of your points (the second is a terrible, terrible choice of default behaviour, in my view). – Fr. Jan 06 '17 at 03:30
  • @Fr. - it seems to be if a date part can be assigned reliably, it will take the current date - `as.Date("01-99", format="%d-%y"); as.Date("01-02", format="%d-%m"); as.Date("01-99", format="%m-%y")` – thelatemail Jan 06 '17 at 03:36

0 Answers0