Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rollback

Rollback of Months


Description

Generating regular sequences of times 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 reverts this process by counting the days 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.

See Also

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
)

DTSg

A Class for Working with Time Series Based on 'data.table' and 'R6' with Largely Optional Reference Semantics

v0.7.0
MIT + file LICENSE
Authors
Gerold Hepp [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.