Learn R Programming

xts (version 0.0-3)

xts: Create Or Test For An xts Time-Series Object

Description

Constructor function for creating an extensible time-series object.

xts is used to create an xts object from raw data inputs.

Usage

xts(x, order.by = index(x), frequency = NULL, ...)

is.xts(x)

Arguments

x
an object containing the time series data
order.by
a corresponding vector of unique times/dates - must be of class Date or POSIXct.
frequency
numeric indicating frequency of order.by. See details.
...
additional attributes to be added. See details.

Value

  • An S3 object of class xts. As it inherits and extends the zoo class, all zoo methods remain valid. Additional attributes assigned may be extracted via the R function attr.

Details

An xts object extends the S3 class zoo from the package of the same name.

The first difference in this extension provides for a requirement that the index values not only be unique, but also must be of class POSIXct or Date, or coercible to such.

The second difference is that the object may now carry additional attributes that may be desired in individual time-series handling. This includes the ability to augment the objects data with meta-data otherwise not cleanly attachable to a standard zoo object.

Examples of usage from finance may include the addition of data for keeping track of data sources, last update times, financial instrument descriptions or details.

The idea behind xts is to offer the user the ability to utilize a standard zoo object, while providing an mechanism to customise the object's meta-data, as well as create custom methods to handle the object in a manner required by the user.

Users may also extend the xts class to new classes to allow for method overloading.

Additional benefits derive from the use of as.xts and reclass, which allow for lossless two-way conversion between common R time-series classes and the xts object structure. See those functions for more detail.

References

zoo:

See Also

as.xts, reclass

Examples

Run this code
library(tseries)
yhoo <- get.hist.quote("YHOO")

sample.xts <- xts(yhoo,order.by=index(yhoo),descr="my ts object")

class(sample.xts)
str(sample.xts)

head(sample.xts)  # attribute 'descr' hidden from view
attr(sample.xts,'descr')

Run the code above in your browser using DataLab