2

尝试查找两天之间的时间间隔时出现上述错误。

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为课堂时间向量,为什么会发生这种情况的任何想法?

提前谢谢你,伊莱

4

1 回答 1

0

尝试从两个日期作为字符数据开始,然后将它们即时转换为 POSIXct。我需要一些示例数据来帮助您进一步排除故障。我遇到了类似的问题,以下代码对我有用。

as.numeric(difftime(as.POSIXct(end_date), as.POSIXct(start_date)))
于 2020-07-28T02:04:09.267 回答