strptime, as.POSIXct and as.Date return unexpected NA

后端 未结 2 1885
长情又很酷
长情又很酷 2020-11-22 05:23

When I try to parse a timestamp in the following format: \"Thu Nov 8 15:41:45 2012\", only NA is returned.

I am using Mac OS X, R 2.15.2 and Rstudio 0.9

2条回答
  •  甜味超标
    2020-11-22 06:06

    Was just messing around with same problem, and found this solution to be much cleaner because there is no need to change any of system settings manually, because there is a wrapper function doing this job in the lubridate package, and all you have to do is set the argument locale:

    date <- c("23. juni 2014", "1. november 2014", "8. marts 2014", "16. juni 2014", "12. december 2014", "13. august 2014")
    df$date <- dmy(df$Date, locale = "Danish")
    [1] "2014-06-23" "2014-11-01" "2014-03-08" "2014-06-16" "2014-12-12" "2014-08-13"
    

提交回复
热议问题