Conversion S3 methods to coerce data objects of arbitrary classes to xts and back, without losing any attributes of the original format.
# 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)
An S3 object of class xts.
Data object to convert. See details for supported types.
Additional parameters or attributes.
See zoo help.
What class should the dates be converted to?
Should the conversion be reversible via reclass()
?
See timeSeries help.
Jeffrey A. Ryan
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.
xts()
, reclass()
, zoo()
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