| tsExtract | R Documentation |
Converts a base R time series object of class ts into two
data frames — one of Date values and one of numeric values —
suitable for passing directly to XY as the x and
y arguments.
XY no longer accepts a ts object directly.
Use tsExtract to prepare the components first, then pass them
to XY. Because the extracted vectors exist in the global
environment rather than in a data frame, include data=NULL in
the XY call.
tsExtract(y.ts, x.name=NULL)
y.ts |
A time series object of class |
x.name |
Optional character string used to name the date column in
the returned |
The function uses time to obtain the fractional-year time
index of each observation and converts it to a Date object.
Supported frequencies are:
365 or 366 | Daily |
52 | Weekly |
12 | Monthly |
4 | Quarterly |
1 | Yearly |
Monthly conversion maps each fractional-year index to the first day of
the corresponding calendar month, which sidesteps the uneven month
lengths that base R's ts indexing does not track.
For a multivariate ts object, the y component contains one column
per time series, named after the original column names.
A list with three components:
x.dates |
A single-column data frame of class |
y |
A data frame of numeric values. One column for a univariate series; one column per series for a multivariate object. |
y.name |
Character string giving the name of the y variable (or the
name from the |
David W. Gerbing (Portland State University; gerbing@pdx.edu)
XY, ts, time
# Monthly airline passenger data (built-in R dataset)
pull <- tsExtract(AirPassengers)
x <- pull$x.dates
y <- pull$y
XY(x,y, data=NULL)
# Quarterly earnings data
pull <- tsExtract(JohnsonJohnson)
x <- pull$x.dates
y <- pull$y
XY(x, y, data=NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.