year_frac: Converting Time Indices to Year Fractions and Back
Description
year_frac computes year fraction corresponding to a time index.
yf2tind performs the reverse computation.
Usage
year_frac(x)
yf2tind(x, type = NULL, tz = NULL)
Value
A numeric vector for year_frac and tind for yf2tind.
Result is of the same length as argument.
Arguments
x
an object of tind class or an R object coercible to it
for year_frac, a numeric vector for yf2tind.
type
a character value determining time index type
(y - years, q - quarters, m - months,
w - weeks, d - dates, t - date-time).
tz
(optional) a character value determining the time zone (the default
NULL is interpreted as the system time zone).
See tzone documentation for information on time zones.
Details
year_fraction returns numeric vector representing time indices
in the form year + year fraction. For years this is equivalent to
as.numeric. Year fraction is determined based on the index
within particular year (minus 1 for all indices except for date-time)
and the number of periods within the year.
E.g., 2001Q1 gives 2001 (2001 + (1 - 1) / 4),
2001Q3 --- 2001.5 (2001 + (3 - 1) / 4),
2010-04 (April 2010) --- 2010.25 (2010 + (4 - 1) / 12),
2000-02-29 (60th day in 2000) --- 2000.1612
(2000 + (60 - 1) / 366, 2000 was a leap year).