dateSeq: Generate Sequences of Dates for Time Series

View source: R/formating.R

dateSeqR Documentation

Generate Sequences of Dates for Time Series

Description

Creates a sequence of dates or times.

Usage

dateSeq(from, to, length.out, by)

Arguments

from

starting date.

to

end date. Can be given instead of length.out parameter

by

character string, increment of the sequence. One of "min", "hour", "day", "week", "month", "quarter", "year". See 'Details'

lenght.out

desired length of the sequence. A non-negative integer. Can be given instead of to parameter.

Details

Depending on the value of by, there are some requirements for the other arguments.

  • For "min" and "hour" the format of from and to should be a correct format for the function as.POSIXct.

  • For "day" and "week" the format of from and to should be a correct format for the function as.Date.

  • For "month" the format of from and to should be a correct format for the function yearmon.

  • For "quarter" the format of from and to should be a correct format for the function yearqtr.

Value

A vector of dates.

See Also

as.POSIXct, as.Date, yearmon, yearqtr.

Examples

dateSeq(from = "2022-01", length.out = 24, by = "month")
dateSeq(from = "2022-01-01", to = "2023-12", by = "month")
dateSeq(from = "2022-01-03", length.out = 12, by = "week")
dateSeq(from = "2022-01-03", to = "2022-03-21", by = "week")

#An example extracting the times of AirPassengers
dateSeq(from = time(AirPassengers)[1], length.out = length(AirPassengers), 
        by = "month")

danipequelangos/CBJTSA documentation built on Oct. 16, 2022, 7:19 p.m.