timegrid: POSIXct Time Grid

View source: R/functions.R

timegridR Documentation

POSIXct Time Grid

Description

Build an equally-spaced sequence of POSIXct timestamps.

Usage

timegrid(from, to, interval,
         exclude.weekends = TRUE, holidays = NULL,
         fromHHMMSS = "080000", toHHMMSS = "220000")

Arguments

from

a vector of length one that inherits from class POSIXt. If there from has a timezone attribute, it will be used for the grid.

to

a vector of length one that inherits from class POSIXt

interval

A character string like “num units”, in which num is a number, and units is sec, min, hour or day. num and units must be separated by white space.

exclude.weekends

logical; default is TRUE

fromHHMMSS

A character vector of length one like “HHMMSS”. Times-of-day earlier than HHMMSS are excluded from the grid. The applicable timezone will be taken from the from argument.

toHHMMSS

A character vector of length one like “HHMMSS”. Times-of-day later than HHMMSS are excluded from the grid. The applicable timezone will be taken from the from argument.

holidays

A vector of class Date, or a character vector in a format that is understood by as.Date, or anything that can be coerced to class Date by as.Date (eg, POSIXt).

Details

timegrid creates an equally-spaced grid of class POSIXct.

Value

a vector of class POSIXct (or a character vector of length zero, in case no valid points remain)

Author(s)

Enrico Schumann

References

B.D. Ripley and K. Hornik. Date-Time Classes. R-News, 1(2):8–12, 2001.

See Also

strftime, date

Examples

from <- as.POSIXct("2012-04-30 08:00:00")
to   <- as.POSIXct("2012-05-04 22:00:00")
timegrid(from, to, interval = "1 hour",
         holidays = as.Date("2012-05-01"))


timegrid(as.POSIXct("2017-06-23 21:00:00"), ## system timezone
         as.POSIXct("2017-06-26 10:00:00"),
         interval = "15 min")
timegrid(as.POSIXlt("2017-06-23 21:00:00", tz = "UTC"),
         as.POSIXlt("2017-06-26 10:00:00", tz = "UTC"),
         interval = "15 min")

datetimeutils documentation built on Nov. 7, 2023, 9:06 a.m.