我在向量中有一系列时间值:
# Source data in %m:%s"
>intervals <- c("1:30", "1:33", "1:29", "1:31", "1:30")
如果我想平均这些值,那么我可以使用该strptime()
函数:
# Averaging with strptime()
> meantime <- mean(strptime(intervals,"%M:%S"))
> meantime
[1] "2013-11-01 00:01:30 PDT"
但我不需要日期和时区的东西。当我想用那个时间值做进一步的计算时,我遇到了问题。假设这些时间值属于 400 m 长的赛道。让我们计算平均速度和配速:
> distance <- as.numeric(400)
> distance
[1] 400
> # Let's calculate the average speed:
> distance/meantime
Error in Ops.POSIXt(distance, meantime) :
'/' not defined for "POSIXt" objects
> # Let's calculate the average pace:
> meantime / distance
Error in Ops.POSIXt(meantime, distance) :
'/' not defined for "POSIXt" objects
所以问题是:是否有一种简单、干净的方法来处理时间值来执行此操作和类似的计算?