as.Date.numeric {zoo} | R Documentation |
Functions to convert numeric and related classes to objects of
class "Date"
representing calendar dates.
## S3 method for class 'numeric': as.Date(x, origin = "1970-01-01", ...) ## S3 method for class 'ts': as.Date(x, offset = 0, ...)
x |
numeric or an object of class "ts" , respectively. |
origin |
A specification of the origin for the dates (x days since origin ). |
offset |
A value added to time(x) . |
... |
Further arguments. Currently not used. |
The as.Date
method for numeric arguments x
interprets x
the number of days since the origin
(default: 1970-01-01).
Negative values are allowed.
The as.Date.ts
inspects time(x)
and frequency(x)
:
If the frequency is 1 or 4 or 12, time(x)
is regarded to be annual,
quarterly or monthly data respectively. If the frequency is something else,
no coercion is done.
The as.Date
methods return an object of class "Date"
.
In the case of as.Date.ts
applied to a yearly, quarterly or monthly
series the earliest date, i.e., first of year, quarter or month, is returned.
Date for details of the date class
as.Date(0) # uses origin = "1970-01-01" # all three result in origin and next 9 days as.Date(0:9) as.Date(0) + 0:9 x <- ts(rnorm(10), start = 0) as.Date(unclass(time(x))) # annual/quarterly/monthly series: xa <- ts(rnorm(10), start = 2001) xq <- ts(rnorm(10), start = 2001, freq = 4) xm <- ts(rnorm(10), start = 2001, freq = 12) as.Date(time(xa)) as.Date(time(xq)) as.Date(time(xm)) # using offset argument xa2 <- ts(rnorm(10)) as.Date(time(xa2), offset = 2000)