tsibble (version 0.8.2)

yearweek: Represent year-week (ISO) starting on Monday, year-month or year-quarter objects

Description

Create or coerce using yearweek(), yearmonth(), or yearquarter()

Usage

yearweek(x)

is_53weeks(year)

yearmonth(x)

yearquarter(x)

Arguments

x

Other object.

year

A vector of years.

Value

Year-week (yearweek), year-month (yearmonth) or year-quarter (yearquarter) objects.

TRUE/FALSE if the year has 53 ISO weeks.

Index functions

The tsibble yearmonth() and yearquarter() function respects time zones of the input x, contrasting to their zoo counterparts.

See Also

interval_pull

Examples

Run this code
# NOT RUN {
# coerce POSIXct/Dates to yearweek, yearmonth, yearquarter
x <- seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by = "1 month")
yearweek(x)
yearmonth(x)
yearmonth(yearweek(x))
yearquarter(x)

# coerce yearmonths to yearquarter
y <- yearmonth(x)
yearquarter(y)

# parse characters
yearmonth(c("2018 Jan", "2018-01", "2018 January"))
yearquarter(c("2018 Q1", "2018 Qtr1", "2018 Quarter 1"))

# seq() and binary operaters
wk1 <- yearweek("2017-11-01")
wk2 <- yearweek("2018-04-29")
seq(from = wk1, to = wk2, by = 2) # by two weeks
wk1 + 0:9
mth <- yearmonth("2017-11")
seq(mth, length.out = 5, by = 1) # by 1 month
mth + 0:9
seq(yearquarter(mth), length.out = 5, by = 1) # by 1 quarter

# different formats
format(c(wk1, wk2), format = "%V/%Y")
format(y, format = "%y %m")
format(yearquarter(mth), format = "%y Qtr%q")
is_53weeks(2015:2016)
# }

Run the code above in your browser using DataLab