Learn R Programming

padr (version 0.6.3)

span_time: Wrapper around seq.POSIXct.

Description

Quickly create a sequence of datetimes from minimal specifications.

Usage

span_time(from, to = NULL, len_out = NULL, by = NULL, tz = "UTC")

Value

An object of class POSIXct.

Arguments

from

Integer or character of length 4 (yyyy), 6 (yyyymm), or 8 ( yyymmdd). Character of length 11 (yyyymmdd hh), 13 (yyyymmdd hhmm), or 15 ( yyyymmdd hhmmss). Indicating the start value of the sequence.

to

Integer or character of length 4 (yyyy), 6 (yyyymm), or 8 ( yyymmdd). Character of length 11 (yyyymmdd hh), 13 (yyyymmdd hhmm), or 15 ( yyyymmdd hhmmss). Indicating the end value of the sequence. Optional.

len_out

The desired length of the sequence. Optional.

by

The desired interval. Optional.

tz

The desired timezone.

Details

Minimal specification of datetimes, sets unspecified date parts to default values. These are 01 for both month and day and 00 for hour, minute, and second.

In addition to from, either to or length must be specified. If the by is not specified, span_time will set the interval to the highest of the specified datetime parts in either from or to. For example, if they are "20160103 01" and "20160108 05" it will be "hour", if they are "2011" and "20110101 021823" it will be "second".

Examples

Run this code
# using to
span_time(2011, 2013)
span_time("2011", "2013")
span_time(2011, 201301)
span_time(2011, 20130101)
span_time(2011, "20110101 0023")
span_time(2011, "20110101 002300")

# using len_out
span_time(2011, len_out = 3)
span_time("2011", len_out = 3)
span_time(2011, len_out = 10, by = "month")
span_time(2011, len_out = 10, by = "day")
span_time(2011, len_out = 10, by = "hour")
span_time("20110101 00", len_out = 10)
span_time("20110101 002300", len_out = 10)

Run the code above in your browser using DataLab