timeBasedSeq: Create a Sequence or Range of Times

timeBasedRangeR Documentation

Create a Sequence or Range of Times

Description

A function to create a vector of time-based objects suitable for indexing an xts object, given a string conforming to the ISO-8601 time and date standard for range-based specification. The resulting series can be of any class supported by xts, including POSIXct, Date, chron, timeDate, yearmon, and yearqtr.

Usage

timeBasedRange(x, ...)

timeBasedSeq(x, retclass = NULL, length.out = NULL)

Arguments

x

An ISO-8601 time-date range string.

...

Unused.

retclass

The return class desired.

length.out

Passed to seq() internally.

Details

timeBasedRange() creates a one or two element numeric vector representing the start and end number of seconds since epoch (1970-01-01). For internal use.

timeBasedSeq() creates sequences of time-based observations using strings formatted according to the ISO-8601 specification. The general format is from/to/by or from::to::by, where to and by are optional when the 'length.out' argument is specified.

The from and to elements of the string must be left-specified with respect to the standard CCYYMMDD HHMMSS form. All dates/times specified will be set to either the earliest point (from) or the latest (to), to the given the level of specificity. For example, ‘1999’ in the from field would set the start to the beginning of 1999. ‘1999’ in the to field would set the end to the end of 1999.

The amount of resolution in the result is determined by the resolution of the from and to component, unless the optional by component is specified.

For example, timeBasedSeq("1999/2008") returns a vector of Dates for January 1st of each year. timeBasedSeq("199501/1996") returns a yearmon vector of 24 months in 1995 and 1996. And timeBasedSeq("19950101/1996") creates a Date vector for all the days in those two years.

The optional by field (the third delimited element to the string), will the resolution heuristic described above and will use the specified by resolution. The possible values for by are: 'Y' (years), 'm' (months), 'd' (days), 'H' (hours), 'M' (minutes), 'S' (seconds). Sub-second resolutions are not supported.

Value

timeBasedSeq() returns a vector of time-based observations. timeBasedRange() returns a one or two element numeric vector representing the start and end number of seconds since epoch (1970-01-01).

When retclass = NULL, the result of timeBasedSeq() is a named list containing elements "from", "to", "by" and "length.out".

Author(s)

Jeffrey A. Ryan

References

International Organization for Standardization: ISO 8601 https://www.iso.org

See Also

timeBased(), xts()

Examples


timeBasedSeq('1999/2008')
timeBasedSeq('199901/2008')
timeBasedSeq('199901/2008/d')
timeBasedSeq('20080101 0830',length=100) # 100 minutes
timeBasedSeq('20080101 083000',length=100) # 100 seconds


joshuaulrich/xts documentation built on Nov. 17, 2024, 6:37 a.m.