r - Mysterious error by parsing French dates on OSX -
i've character vector dates in french. convert them date format in r. seems work there mysterious errors. instance, r recognize "30 juin 2012" not "30 juillet 2012" :
> as.date("30 juin 2012", format = "%d %b %y") [1] "2012-06-30" > as.date("28 février 2012", format = "%d %b %y") [1] "2012-02-28" > as.date("30 juillet 2012", format = "%d %b %y") [1] na
do have explanation ?
ps : local setting french utf8
> sys.getlocale() [1] "fr_fr.utf-8/fr_fr.utf-8/fr_fr.utf-8/c/fr_fr.utf-8/fr_fr.utf-8"
i don't have explanation, have solution. having had similar problems german numbers using "," instead of "." decimals , different ways of writing dates too. here's data not in correct format:
a<-"30 juillet 2012" b<-gsub(pattern="juillet", a, replacement="july") as.date(b, format="%d %b %y") [1] "2012-07-30"
hope helps out. if "july" doesn't work on system, replace 7. so
a<-"30 juillet 2012" b<-gsub(pattern="juillet", a, replacement="/ 7 /") b<-gsub(pattern="|| ", b, replacement="") as.date(b, format= "%d/%m/%y")
greetings, ben
Comments
Post a Comment