转换一列日期时间文本时出现 as.POSIXlt 错误
我有一列日期时间格式的文本字段,我想将其转换为日期时间对象,以便我可以对它们进行合理的排序。我正在使用data.table
。
我的专栏看起来有点像这样:
Test Date
2022-01-05 04:47:05.763
NA
2022-02-16 09:51:00.000
NA
NA
2022-02-06 10:56:00.000
我将此 data.table dt 转换为日期时间对象的代码如下(旨在通过将 NA 值转换为默认日期时间来处理它们):
dt[, `Test Date` := as.POSIXlt(ifelse(is.na(`Test Date`), '2022-01-01 00:00:00', `Test Date`))]
我的错误行是:
Error in as.POSIXlt.character(ifelse(is.na(`Test Date`), "2021-01-01 00:00:00", :
character string is not in a standard unambiguous format
不确定哪里出错了(不确定哪些行导致了错误)。
平台 x86_64-w64-mingw32
,使用 RStudio 的 R 4.1.2
I've got a column of text fields that are in a datetime format, which I'd like to convert to datetime objects so I can sort them sanely. I'm using data.table
.
My column looks a little something like this:
Test Date
2022-01-05 04:47:05.763
NA
2022-02-16 09:51:00.000
NA
NA
2022-02-06 10:56:00.000
My code to convert this data.table dt
to datetime objects is as follows (meant to handle NA values by converting them to a default datetime):
dt[, `Test Date` := as.POSIXlt(ifelse(is.na(`Test Date`), '2022-01-01 00:00:00', `Test Date`))]
My error on that line is:
Error in as.POSIXlt.character(ifelse(is.na(`Test Date`), "2021-01-01 00:00:00", :
character string is not in a standard unambiguous format
Unsure where I'm going wrong (unsure which rows are causing the error).
Platform x86_64-w64-mingw32
, R 4.1.2
using RStudio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论