Learn R Programming

bsts (version 0.9.5)

regularize.timestamps: Produce a Regular Series of Time Stamps

Description

Given an set of timestamps that might contain duplicates and gaps, produce a set of timestamps that has no duplicates and no gaps.

Usage

RegularizeTimestamps(timestamps)

# S3 method for default RegularizeTimestamps(timestamps)

# S3 method for numeric RegularizeTimestamps(timestamps)

# S3 method for Date RegularizeTimestamps(timestamps)

# S3 method for POSIXt RegularizeTimestamps(timestamps)

Arguments

timestamps

A set of (possibly irregular or non-unique) timestamps. This could be a set of integers (like 1, 2, , 3...), a set of numeric like (1945, 1945.083, 1945.167, ...) indicating years and fractions of years, a Date object, or a POSIXt object.

Value

A set of regularly spaced timestamps of the same class as the argument (which might be NULL).

Examples

Run this code
# NOT RUN {
  first <- as.POSIXct("2015-04-19 08:00:04")
  monthly <- seq(from = first, length.out = 24, by = "month")
  skip.one <- monthly[-8]
  has.duplicates <- monthly
  has.duplicates[2] <- has.duplicates[3]

  reg1 <- RegularizeTimestamps(skip.one)
  all.equal(reg1, monthly) ## TRUE

  reg2 <- RegularizeTimestamps(has.duplicates)
  all.equal(reg2, monthly)  ## TRUE

# }

Run the code above in your browser using DataLab