R, strptime(), %b, trying to convert character to date format

故事扮演 提交于 2019-12-06 13:58:54

strptime will recognize abbreviated names in the current locale. You can change your current locale to spanish, transform your dates, then change it back to the original setting:

#save your current locale
original_locale<-Sys.getlocale(category = "LC_TIME")

#change it to spanish
Sys.setlocale(category = "LC_TIME", locale = "es_ES.UTF-8")

#transform your dates
data<-c("24-feb-15","26-ene-15","29-dic-14")
strptime(data,format="%d-%b-%y")

#[1] "2015-02-24 GMT" "2015-01-26 GMT" "2014-12-29 GMT"

#change it back to the original setting
Sys.setlocale(category = "LC_TIME", locale = original_locale)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!