將字符或數字向量轉換為具有指定小時數、分鍾數和秒數的周期對象。 hms()
將除 '-' 之外的所有非數字字符識別為分隔符('-' 用於否定 durations
)。解析完小時、分鍾和秒後,剩餘的輸入將被忽略。
用法
ms(..., quiet = FALSE, roll = FALSE)
hm(..., quiet = FALSE, roll = FALSE)
hms(..., quiet = FALSE, roll = FALSE)
參數
- ...
-
時分秒三元組的字符向量
- quiet
-
合乎邏輯的。如果是
TRUE
,函數將在不顯示常規消息的情況下進行計算。 - roll
-
合乎邏輯的。如果是
TRUE
,則如果較小的單位超出了常規限製,則將滾動到較高的單位。例如,hms("01:59:120", roll = TRUE)
產生周期“2H 1M 0S”。
例子
ms(c("09:10", "09:02", "1:10"))
#> [1] "9M 10S" "9M 2S" "1M 10S"
ms("7 6")
#> [1] "7M 6S"
ms("6,5")
#> [1] "6M 5S"
hm(c("09:10", "09:02", "1:10"))
#> [1] "9H 10M 0S" "9H 2M 0S" "1H 10M 0S"
hm("7 6")
#> [1] "7H 6M 0S"
hm("6,5")
#> [1] "6H 5M 0S"
x <- c("09:10:01", "09:10:02", "09:10:03")
hms(x)
#> [1] "9H 10M 1S" "9H 10M 2S" "9H 10M 3S"
hms("7 6 5", "3:23:::2", "2 : 23 : 33", "Finished in 9 hours, 20 min and 4 seconds")
#> [1] "7H 6M 5S" "3H 23M 2S" "2H 23M 33S" "9H 20M 4S"
相關用法
- R lubridate hour 獲取/設置日期時間的小時部分
- R lubridate DateTimeUpdate 更改日期對象的組成部分
- R lubridate stamp 基於人性化模板設置日期和時間格式
- R lubridate interval 用於創建和操作 Interval 對象的實用程序
- R lubridate is.difftime x 是 difftime 對象嗎?
- R lubridate as_date 將對象轉換為日期或日期時間
- R lubridate date 獲取/設置日期時間的日期部分
- R lubridate round_date 日期時間對象的舍入、取整和取整方法
- R lubridate make_difftime 創建一個 difftime 對象。
- R lubridate is.timespan x 是時間長度嗎?
- R lubridate with_tz 獲取不同時區的日期時間
- R lubridate mplus 在日期中添加和減去月份,但不超過新月份的最後一天
- R lubridate cyclic_encoding 日期時間的循環編碼
- R lubridate as.interval 將對象更改為間隔
- R lubridate second 獲取/設置日期時間的秒部分
- R lubridate quarter 獲取日期時間的財政季度和學期
- R lubridate posix_utils 各種 POSIX 實用程序
- R lubridate date_decimal 將小數轉換為日期
- R lubridate as.duration 將對象更改為持續時間
- R lubridate minute 獲取/設置日期時間的分鍾部分
- R lubridate month 獲取/設置日期時間的月份部分
- R lubridate duration 創建一個持續時間對象。
- R lubridate leap_year 一年是閏年嗎?
- R lubridate local_time 從日期時間向量獲取當地時間。
- R lubridate make_datetime 從數字表示高效創建日期時間
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Parse periods with hour, minute, and second components。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。