strptime,作為.POSIXct和as.Date返回意外的NA。當(dāng)我試圖以下格式解析時間戳?xí)r:“清華11月8日15:41:45 2012”,僅限NA會被歸還。我使用的是MacOSX,R2.15.2和RStudio 0.97.237。我的操作系統(tǒng)語言是荷蘭語:我想這與它有關(guān)。當(dāng)我嘗試strptime, NA返回:var <- "Thu Nov 8 15:41:45 2012"strptime(var, "%a %b %d %H:%M:%S %Y")# [1] NA也沒有as.POSIXct工作:as.POSIXct(var, "%a %b %d %H:%M:%S %Y")# [1] NA我也試過as.Date在上面的字符串上但是沒有%H:%M:%S構(gòu)成部分:as.Date("Thu Nov 8 2012", "%a %b %d %Y")# [1] NA知道我可能做錯了什么嗎?
3 回答

RISEBY
TA貢獻1856條經(jīng)驗 獲得超5個贊
lubridate
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"

翻過高山走不出你
TA貢獻1875條經(jīng)驗 獲得超3個贊
locale
lubridate
orig_locale <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", locale); on.exit(Sys.setlocale("LC_TIME", orig_locale))
- 3 回答
- 0 關(guān)注
- 1008 瀏覽
添加回答
舉報
0/150
提交
取消