R Read abbreviated month form a date that is not in English

后端 未结 2 1238
南旧
南旧 2020-12-20 20:45

I have a text file that includes dates, and want to convert it to a datatable.

Converting the dates such as 03-FEB-2011 can be done with

data$fecha &         


        
2条回答
  •  醉酒成梦
    2020-12-20 21:44

    As my previous comment, here is a complete and tested answer. As I've said you have to set your locale to the one right for your data (in this case spanish).

    The code that allows you to do that is the following:

    Sys.setlocale(locale="es_ES.UTF-8")
    

    you can see the complete list of available locales with system("locale -a", intern = TRUE) (not sure if it works well on Windows systems).

    Here is an example:

    x <- c("03-Ago-2011", "21-Ene-2012")
    as.Date(x, format = "%d-%b-%Y")
    [1] "2011-08-03" "2012-01-21"
    

提交回复
热议问题