为了在R中将chr转换为正确的日期格式,我使用了下面的示例,返回一个错误。
> as.POSIXlt(strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z"))
[1] NA发布于 2017-08-08 18:33:40
在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"https://stackoverflow.com/questions/45565986
复制相似问题