我有小時的時間數據:分鐘:秒:毫秒。我也有一個關於每個時間點發生什麼的描述符。我的數據集的例子如下:從毫秒到分鐘回合
StartTime <- c("00:00:00:00", "00:00:14:04", "00:01:51:06", "00:03:30:02")
Events <- c("Start whistle", "Pass", "Shot", "Pass")
RawData <- data.frame(StartTime, Events)
我現在想創建根據出場時間,除此之外,該新列,從StartTime
列。我的預期輸出是:
MinutesPlayed <- c(0, 0, 2, 3)
我曾嘗試使用下面的代碼圓,但它包括日期(不需要我的工作),並仍保持時間H:M:S格式。
RawData$MinutesPlayed <- strptime(RawData$StartTime, "%H:%M:%S")
我在哪裏錯了?
第四組數字代表什麼?毫秒? –
是的,它表示毫秒。道歉,我應該在帖子中明確表達,而不僅僅是標題。 – user2716568
'difftime'具有很好的單位功能:'difftime(as.POSIXct(RawData $ StartTime,tz ='UTC',format ='%T'),Sys.Date(),units ='mins')' – alistaire