shift_dates | R Documentation |
Shifts a vector of dates to start on the same day-of-year in a specified origin year while preserving the relative difference in days among the observations. This way the temporal pattern (e.g., seasonality) inherent to the original dates will also be preserved in the shifted dates.
shift_dates(x, origin = "1970-01-01")
x |
A vector of date strings or Date objects representing the sequence to shift. |
origin |
A date string or Date object specifying the desired origin year for the shifted dates. Default is "1970-01-01". |
The primary goal of this function is to align a sequence of dates based on the day-of-year in a desired origin year. This can be particularly useful for comparing or visualizing two or more time series with different absolute dates but aiming to align them based on the day-of-year or another relative metric.
A vector of Date objects with the shifted dates starting on the same day-of-year in the specified origin year.
x <- c("2011-09-14", "2011-09-30", "2011-10-16", "2011-11-01")
shift_dates(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.