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, ...) ## S3 method for class 'integer': as.Date(x, ...) ## S3 method for class 'ts': as.Date(x, offset = 0, ...)
x |
An object of class "numeric" , "integer"
or "ts" respectively. |
offset |
A value added to time(x) . |
... |
Further arguments. Currently not used. |
The as.Date.integer
method interprets the argument x
as
the number of days since the origin 1970-01-01 so that the origin
corresponds to 0. Negative values are allowed.
The as.Date.numeric
method like the as.Date.integer
method applied to floor(x)
.
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) # origin, i.e. 1970-01-01 # all three result in origin and next 9 days as.Date(0:9) as.Date(0) + 0:9 myts <- ts(rnorm(10), start = 0) as.Date(unclass(time(myts))) # both result in ten firsts of year starting 2001-01-01 as.Date(ts(rnorm(10)), offset = 2000) as.Date(ts(rnorm(10), start = 2001)) # both result in ten firsts of month starting with 1990-01-01 as.Date(ts(rnorm(10), start = c(90,1), freq = 12), offset = 1900) as.Date(ts(rnorm(10), start = c(1990,1), freq = 12))