View source: R/yeardec2dateSeq.R
yeardec2dateSeq | R Documentation |
The function is helpful for quickly defining a vector of dates that e.g. can be used to define gridlines in a plot.
yeardec2dateSeq(from, to, by, ...)
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 |
... |
Further arguments to pass to |
A vector of class "Date"
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.