我在尝试找到两天之间的间隔时遇到上述错误。
x <- as.POSIXct(strptime(as.character(wo_data$In.Progress.time),"%m/%d/%Y %I:%M:%S %p"))
class(x)
# [1] "POSIXct" "POSIXt"
wo_data$super.schedule.inprogress <-
as.numeric(difftime(x, wo_data$schedule.time, units = "hours"))
# Error in as.POSIXct.default(time1) :
# do not know how to convert 'time1' to class POSIXct
# In addition: Warning messages:
# 1: Too many values at 103 locations: 608, 617, 659, 724, 753, 754, 755,
# 802, 1029, 1030, 1031, 1037, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, ...
# 2: Too few values at 3170 locations: 60, 109, 110, 112, 114, 118, 119,
# 120, 121, 122, 161, 163, 167, 172, 197, 202, 206, 207, 208, 209, ...
# 3: 3 failed to parse.
即使R成功将wo_data$In.Progress.time
转换为课堂时间向量,也会发生任何想法?
提前谢谢你, 利
答案 0 :(得分:0)
尝试从两个日期开始作为字符数据,然后将它们即时转换为POSIXct。我需要一些示例数据来帮助您进行进一步的故障排除。我遇到了类似的问题,下面的代码对我有用。
as.numeric(difftime(as.POSIXct(end_date), as.POSIXct(start_date)))