季度將一年分為四分之一。學期將一年分為兩半。
用法
quarter(
x,
type = "quarter",
fiscal_start = 1,
with_year = identical(type, "year.quarter")
)
semester(x, with_year = FALSE)
參數
- x
-
POSIXct、POSIXlt、Date、chron、yearmon、yearqtr、zoo、zooreg、timeDate、xts、its、ti、jul、timeSeries、fts 類的日期時間對象或可以使用 as.POSIXlt 轉換的任何其他對象
- type
-
該季度返回的格式。可以是 "quarter" - 返回數字季度(默認)、"year.quarter" 返回小數數字year.quarter、"date_first" 或 "date_last" 之一,返回季度開始結束時的日期。
- fiscal_start
-
表示會計年度開始月份的數字。
- with_year
-
邏輯指示是否包含季度或學期(已棄用;改用
type
參數)。
例子
x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31"))
quarter(x)
#> [1] 1 2 3 4
quarter(x, type = "year.quarter")
#> [1] 2012.1 2012.2 2012.3 2012.4
quarter(x, type = "year.quarter", fiscal_start = 11)
#> [1] 2012.2 2012.3 2012.4 2013.1
quarter(x, type = "date_first", fiscal_start = 11)
#> [1] "2012-02-01" "2012-05-01" "2012-08-01" "2012-11-01"
quarter(x, type = "date_last", fiscal_start = 11)
#> [1] "2012-04-30" "2012-07-31" "2012-10-31" "2013-01-31"
semester(x)
#> [1] 1 1 2 2
semester(x, with_year = TRUE)
#> [1] 2012.1 2012.1 2012.2 2012.2
相關用法
- 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 posix_utils 各種 POSIX 實用程序
- R lubridate date_decimal 將小數轉換為日期
- R lubridate as.duration 將對象更改為持續時間
- R lubridate hour 獲取/設置日期時間的小時部分
- R lubridate minute 獲取/設置日期時間的分鍾部分
- R lubridate month 獲取/設置日期時間的月份部分
- R lubridate duration 創建一個持續時間對象。
- R lubridate leap_year 一年是閏年嗎?
- R lubridate local_time 從日期時間向量獲取當地時間。
- R lubridate make_datetime 從數字表示高效創建日期時間
- R lubridate week 獲取/設置日期時間的周組成部分
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Get the fiscal quarter and semester of a date-time。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。