[英]Why does diff.time Return NA values, console shows no error.?
I am here trying to calculate the time difference between two date formats, first, I have been faced with various errors such as我在这里尝试计算两种日期格式之间的时间差,首先,我遇到了各种错误,例如
as.POSIXlt.character
: character string is not in a standard unambiguous format as.POSIXlt.character
:字符串不是标准的明确格式NA
values added by coercionNA
值however, with trials, I have reached this next line of code that runs with no errors or warnings but the return values are all NA
但是,通过试验,我已经达到了下一行代码,它运行时没有错误或警告,但返回值都是
NA
Rides_cleaned <-
Rides %>%
drop_na() %>%
distinct() %>%
mutate(rideduration=difftime(as.numeric(as.POSIXct(ended_at,format = "%m/%d/%Y %H:%M:%S %p")),
as.numeric(as.POSIXct(started_at,format = "%m/%d/%Y %H:%M:%S %p")), units = "mins"))
Make sure to use the correct date format, as.numeric
isn't needed either:确保使用正确的日期格式,也不需要
as.numeric
:
Rides <- data.frame(started_at="6/4/21 7:45",ended_at="6/4/21 7:46")
Rides %>%
drop_na() %>%
distinct() %>%
mutate(rideduration=difftime(as.POSIXct(ended_at,format = "%m/%d/%y %H:%M"),
as.POSIXct(started_at,format = "%m/%d/%y %H:%M"),
units = "mins"))
# started_at ended_at rideduration
#1 6/4/21 7:45 6/4/21 7:46 1 mins
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.