将中的chr时间转换为R中的实际时间



所以我试图将写在chr-in中的F1-Laptime转换为时间,然后我可以将其绘制为直方图。

这就是我尝试过的。但没有成功。

lapTimes <- lapTimes %>% mutate(Time = ms(Time))
format(as.POSIXct(lapTimes$time, tz = ""), format = "%M:%S.%OS")

时间看起来总是这样的1分11秒11,先是分钟,然后是秒,然后是毫秒。如果有人有什么想法,我会通知你的。

提前感谢!:D

如前所述,我假设您的数据如下所示:

laptime <- c("1:11.111", "2:02.2222")

这表示的是时间间隔,而不是日期时间。因此,您可以将其转换为difftime类,然后根据需要转换为数字。

as.difftime(laptime, format = "%M:%S.%OS")
#Time differences in mins
#[1] 1.183333 2.033333

由于您没有提供示例数据,我假设它存储为一个字符。

laptime <- "1:11.111"
> as.POSIXlt.character(laptime, format = "%M:%S.%OS", tz = 'GMT')
[1] "2021-01-14 00:01:11 GMT"
# compute time difference from dates
laptime <- "1:11.111"
t2 <- as.POSIXlt.character(laptime, format = "%M:%S.%OS", tz = 'GMT')
t1 <- as.Date(t2)
> difftime(t2, t1)
Time difference of 1.183333 mins

你也可以看看这个链接,看起来对你的特定问题非常有用:https://rstudio-pubs-static.s3.amazonaws.com/276999_042092be8e31414f82ef4f41e31fe5c8.html

最新更新