yeardec2dateSeq: Year-decimal to date sequence wrapper

View source: R/yeardec2dateSeq.R

yeardec2dateSeqR Documentation

Year-decimal to date sequence wrapper

Description

The function is helpful for quickly defining a vector of dates that e.g. can be used to define gridlines in a plot.

Usage

yeardec2dateSeq(from, to, by, ...)

Arguments

from

numeric A year-decimal value to convert to the starting date.

to

numeric A year-decimal value to convert to the ending date.

by

increment of the sequence. Optional. See ‘Details’ in seq.Date.

...

Further arguments to pass to seq.Date.

Value

A vector of class "Date".

Examples

# the long way
seq.Date(as.Date("2000-01-01"), as.Date("2010-01-01"), by = "year")

# the shorter way 
yeardec2dateSeq(2000, 2010, by = "year")

# use other 'by' settings
yeardec2dateSeq(2000, 2001.99, by = "month")

# use in defining grid lines
set.seed(1)
x <- seq.Date(as.Date("2000-01-01"), as.Date("2003-12-31"), by = "day")
y <- cumsum(rnorm(length(x)))
plot(x,y, t = "l")
abline(v = yeardec2dateSeq(2000, 2010, by = "3 month"), lty = 3, col = 8)


marchtaylor/sinkr documentation built on June 15, 2025, 1:17 a.m.