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
  • 54,400
  • 17
  • 144
  • 178
vinod
  • 87
  • 1
  • 3
  • 7

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
  • 42,475
  • 9
  • 93
  • 111
  • +1 %y is just getting the first two digits of the four digit year. %Y should fix. – km1 Jul 31 '13 at 16:32