Learn R Programming

xts (version 0.14.1)

as.xts.Date: Convert Objects To and From xts

Description

Conversion S3 methods to coerce data objects of arbitrary classes to xts and back, without losing any attributes of the original format.

Usage

# S3 method for Date
as.xts(x, ...)

# S3 method for POSIXt as.xts(x, ...)

# S3 method for data.frame as.xts( x, order.by, dateFormat = "POSIXct", frequency = NULL, ..., .RECLASS = FALSE )

# S3 method for irts as.xts(x, order.by, frequency = NULL, ..., .RECLASS = FALSE)

# S3 method for matrix as.xts( x, order.by, dateFormat = "POSIXct", frequency = NULL, ..., .RECLASS = FALSE )

# S3 method for timeDate as.xts(x, ...)

# S3 method for timeSeries as.xts( x, dateFormat = "POSIXct", FinCenter, recordIDs, title, documentation, ..., .RECLASS = FALSE )

# S3 method for ts as.xts(x, dateFormat, ..., .RECLASS = FALSE)

as.xts(x, ...)

xtsible(x)

# S3 method for yearmon as.xts(x, ...)

# S3 method for yearqtr as.xts(x, ...)

# S3 method for zoo as.xts(x, order.by = index(x), frequency = NULL, ..., .RECLASS = FALSE)

Value

An S3 object of class xts.

Arguments

x

Data object to convert. See details for supported types.

...

Additional parameters or attributes.

order.by, frequency

See zoo help.

dateFormat

What class should the dates be converted to?

.RECLASS

Should the conversion be reversible via reclass()?

FinCenter, recordIDs, title, documentation

See timeSeries help.

Author

Jeffrey A. Ryan

Details

A simple and reliable way to convert many different objects into a uniform format for use within R.

as.xts() can convert objects of the following classes into an xts object: object: timeSeries, ts, matrix, data.frame, and zoo. xtsible() safely checks whether an object can be converted to an xts object.

Additional name = value pairs may be passed to the function to be added to the new object. A special print.xts() method ensures the attributes are hidden from view, but will be available via R's standard attr() function, as well as the xtsAttributes() function.

When .RECLASS = TRUE, the returned xts object internally preserves all relevant attribute/slot data from the input x. This allows for temporary conversion to xts in order to use zoo and xts compatible methods. See reclass() for details.

See Also

xts(), reclass(), zoo()

Examples

Run this code

if (FALSE) {
# timeSeries
library(timeSeries)
x <- timeSeries(1:10, 1:10)

str(as.xts(x))
str(reclass(as.xts(x)))
str(try.xts(x))
str(reclass(try.xts(x)))
}

Run the code above in your browser using DataLab