as.Date.numeric

0th

Percentile

Date Conversion Functions from Numeric, Integer and ts Objects

Functions to convert numeric and related classes to objects of class "Date" representing calendar dates.

Keywords
utilities, chron
Usage
## S3 method for class 'numeric':
as.Date(x, origin = "1970-01-01", \dots)
## S3 method for class 'ts':
as.Date(x, offset = 0, \dots)
Arguments
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.
Details

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.

Value

  • 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.

See Also

Date for details of the date class

Aliases
  • as.Date.numeric
  • as.Date.ts
Examples
# uses origin = "1970-01-01"
as.Date(0) 

# 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)
Documentation reproduced from package zoo, version 1.5-6, License: GPL-2

Community examples

Looks like there are no examples yet.