2017-08-08 88 views
0

試圖將chr轉換爲適當的日期格式,我使用下面的示例,返回一個錯誤。as.POSIXlt返回不適用

> as.POSIXlt(strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z")) 
[1] NA 

回答

0

as.POSIXlt is producing NA in R的評論,我意識到我有我的會話錯誤LC_TIME集。

> Sys.getlocale("LC_TIME") 
[1] "German_Germany.1252" 

上述格式爲英文,而非德文。所以改變語言環境應該是解決方案,並且瞧!

> Sys.setlocale("LC_TIME", "English") 
[1] "English_United States.1252" 
> as.POSIXlt(strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z")) 
[1] "2010-03-23 19:36:38" 
+0

'strptime'返回一個POSIXlt對象。你可以放棄'as.POSIXlt' – Dave2e