A client sent me an Excel file with dates formatted as e.g 3/15/2012 for March 15. I saved this as a .csv file and then used
camm$Date <- as.Date(camm$Date, "%m/%d/%y")
but this gave me values starting in the year 2020!
I tried to reformat the dates in the original csv file so that they were e.g. 03/14/2013 but was unable to do so.
Any help appreciated
To complete the picture, you might also try the recently introduced (2016-09) package
anytime
which takes advantage of theBoost
C++ libraries:Use capital
Y
inas.Date
call instead. This should do the trick:From the help file's examples you can realize when year is full specified you should use
%Y
otherwise%y
for example:You can see that in your example the Year format is 2012 then you should use
%Y
, and in the other example (taken from theas.Date
help file) Year format is 92 then using%y
is the correct way to go. Seeas.Date
for further details.You might also give a try to the
lubridate
package if you do not want to deal with the hieroglyphics :)PS.: of course I do not encourage anyone to use any extra dependencies, this answer was just posted here as an alternative (and quick to remeber) solution