rollback: Rollback of months

View source: R/utils.R

rollbackR Documentation

Rollback of months

Description

Generating regular sequences of time with the help of seq.POSIXt can have undesirable effects. This function “first advances the month without changing the day: if this results in an invalid day of the month, it is counted forward into the next month”. Monthly or yearly sequences starting at the end of a month with 30 or 31 days (or 29 in case of a leap year) therefore do not always fall on the end of shorter months. rollback fixes this by counting the days of affected months backwards again.

Usage

rollback(.dateTime, periodicity)

Arguments

.dateTime

A POSIXct vector.

periodicity

A character string specifying a multiple of month(s) or year(s). See seq.POSIXt for further information.

Value

Returns a POSIXct vector.

Examples

# rollback monthly time series
by <- "1 month"
rollback(
  .dateTime = seq(
    from = as.POSIXct("2000-01-31", tz = "UTC"),
    to = as.POSIXct("2000-12-31", tz = "UTC"),
    by = by
  ),
  periodicity = by
)


gisler/DTSg documentation built on Dec. 12, 2024, 1:23 a.m.