as.POSIXlt返回NA

时间:2017-08-08 10:33:40

标签: r datetime locale

尝试将chr转换为R中的正确日期格式,我使用以下示例,返回错误。

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

1 个答案:

答案 0 :(得分:0)

根据对as.POSIXlt is producing NA in R的评论,我意识到我的会话设置错误LC_TIME

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

上面的格式是英文,而不是德文。因此,更改区域设置应该是解决方案并且vo!

> 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"