1

I am running into some date issues when working with Dates in R.

Here's my situation-

I have a data set based on dates and finally got the Date field converted from character to Date in R using the following code

o1$Date <- as.Date(o1$Date , "%m/%d/%y")

(My dataset is o1 and Date is the name of my Date column)

My Date column has the following values

"1/1/2013"  "1/1/2014"  "1/10/2013" "1/10/2014" "1/11/2013" "1/11/2014"

However when I convert the Char to Date I get the following Dates

"2020-01-01" "2020-01-01" "2020-01-10" "2020-01-10" "2020-01-11"

Any suggestions on what the problem could be and how to work around it?

Ricardo Saporta
  • 51,025
  • 13
  • 129
  • 166
vinod
  • 87
  • 2
  • 7
  • Possible duplicate of [Convert character to Date in R](https://stackoverflow.com/questions/4310326/convert-character-to-date-in-r) – divibisan Mar 14 '19 at 15:36

1 Answers1

3

look at ?strptime to see the formatting options for times and dates. You need to use %Y rather than %y which is for a 2 digit year.

Justin
  • 39,207
  • 8
  • 85
  • 105
  • +1 %y is just getting the first two digits of the four digit year. %Y should fix. – km1 Jul 31 '13 at 16:32