该函数给出了意想不到的结果,并显示错误消息。 看看我发现了什么
as.ITime(reff[["Saida"]])
[1] "05:24:00"
as.ITime(df[,"Saida"])
[1] "04:30:00"
之后,我执行:
diff(reff[["Saida"]], df[,"Saida"])
Error in substring(paste("0", hh, sep = ""), nchar(paste(hh))) : invalid substring arguments
我该如何解决这个问题?有什么想法出现这个错误?
PS:
这是df
structure(list(Linha = 307L, Sentido = 1L, Saida = structure(16200L, class = "ITime"),
Chegada = structure(16740L, class = "ITime"), Catraca = 0L,
Embarcado = 25L, dia = "sexta", feriado = TRUE, isOL = FALSE,
antes = TRUE, proximo = TRUE), .Names = c("Linha", "Sentido",
"Saida", "Chegada", "Catraca", "Embarcado", "dia", "feriado",
"isOL", "antes", "proximo"), row.names = 747092L, class = "data.frame")
这是reff
structure(list(Linha = 307L, Sentido = 1L, Saida = structure(19440L, class = "ITime"),
Chegada = structure(20700L, class = "ITime"), Catraca = 35L,
Embarcado = 125L, dia = "sexta", feriado = TRUE, isOL = TRUE,
antes = TRUE, proximo = TRUE), .Names = c("Linha", "Sentido",
"Saida", "Chegada", "Catraca", "Embarcado", "dia", "feriado",
"isOL", "antes", "proximo"), row.names = 747094L, class = "data.frame")
答案 0 :(得分:2)
您需要difftime
(请参阅?difftime
)而不是diff
(请参阅?diff
):
difftime(reff[["Saida"]], df[,"Saida"])
时差54分钟
diff
用于创建1个变量的滞后。 difftime
用于区分2个时间/日期变量。