2
x <- c("1-jan-60", "2-jan-89", "31-mar-89", "30-jul-93")
z <- as.Date(x, "%d-%b-%y")
z
"2060-01-01" "1989-01-02" "1989-03-31" "1993-07-30"

I converted character date into date format it is giving as wrong output.

the output should be

"1960-01-01" "1989-01-02" "1989-03-31" "1993-07-30"
Gopala
  • 10,363
  • 7
  • 45
  • 77
ankit agarwal
  • 51
  • 1
  • 4
  • 3
    Y2K problem revisited... ;-) How should the code know that you mean 1960 and not 2060? The latter is closer to the current date. – RHertel May 16 '16 at 13:26
  • aahh , that is why `-69` gives `1969` and `-68` gives `2068` – Sotos May 16 '16 at 13:28
  • 2
    `?strptime` explanation of the `%y` tag says "On input, values 00 to 68 are prefixed by 20 and 69 to 99 by 19" – Ben Bolker May 16 '16 at 13:29
  • 1
    @Sotos I didn't want to say that R always selects the closest year in such cases. Ben Bolker has clarified how this is done. What I wanted to point out is that the date is ambiguous, and that it seems plausible that when a difference of about 50 years is involved it would be a good idea to specify the century. – RHertel May 16 '16 at 13:34
  • http://www.stat.berkeley.edu/~s133/dates.html: `Internally, Date objects are stored as the number of days since January 1, 1970, using negative numbers for earlier dates.` – zyurnaidi May 16 '16 at 13:36
  • @RHertel, Yes I just did the math :) – Sotos May 16 '16 at 13:37
  • @zyurnaidi : interesting fact, but irrelevant to the current question – Ben Bolker May 16 '16 at 13:59

0 Answers0