make_difftime()
創建具有指定單位數的 difftime 對象。不同單位的條目是累積的。 difftime 以各種單位顯示持續時間,但這些單位是為方便起見而給出的估計值。底層對象始終記錄為固定的秒數。
參數
- num
-
可選秒數
- units
-
一個字符向量,列出用於顯示返回值的單位類型(請參閱示例)。如果
units
是"auto"(默認值),則會自動計算顯示單位。在數據處理中將difftime
對象轉換為數值時,這可能會產生不良影響。 - ...
-
要包含在 difftime 中的時間單位及其數量的列表。支持秒、分鍾、小時、天和周。通常僅存在
num
或...
之一。如果兩者都存在,則difftime
對象被連接。
細節
從概念上講,difftime 對象是一種持續時間。它們測量準確的時間流逝,但並不總是與以較大時間單位(例如小時、月和年)進行的測量保持一致。這是因為較大時間單位的長度可能會受到閏年和夏令時等慣例的影響。潤滑提供第二個類來測量持續時間,即 Duration 類。
例子
make_difftime(1)
#> Time difference of 1 secs
make_difftime(60)
#> Time difference of 1 mins
make_difftime(3600)
#> Time difference of 1 hours
make_difftime(3600, units = "minute")
#> Time difference of 60 mins
# Time difference of 60 mins
make_difftime(second = 90)
#> Time difference of 1.5 mins
# Time difference of 1.5 mins
make_difftime(minute = 1.5)
#> Time difference of 1.5 mins
# Time difference of 1.5 mins
make_difftime(second = 3, minute = 1.5, hour = 2, day = 6, week = 1)
#> Time difference of 13.08441 days
# Time difference of 13.08441 days
make_difftime(hour = 1, minute = -60)
#> Time difference of 0 secs
# Time difference of 0 secs
make_difftime(day = -1)
#> Time difference of -1 days
# Time difference of -1 days
make_difftime(120, day = -1, units = "minute")
#> Time differences in mins
#> [1] 2 -1440
# Time differences in mins
相關用法
- R lubridate make_datetime 從數字表示高效創建日期時間
- R lubridate mplus 在日期中添加和減去月份,但不超過新月份的最後一天
- R lubridate minute 獲取/設置日期時間的分鍾部分
- R lubridate month 獲取/設置日期時間的月份部分
- 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 is.timespan x 是時間長度嗎?
- R lubridate with_tz 獲取不同時區的日期時間
- 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 hour 獲取/設置日期時間的小時部分
- R lubridate duration 創建一個持續時間對象。
- R lubridate leap_year 一年是閏年嗎?
- R lubridate local_time 從日期時間向量獲取當地時間。
- R lubridate week 獲取/設置日期時間的周組成部分
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Create a difftime object.。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。