indexClass {xts} | R Documentation |
Generic functions to extract, replace, and format the class of the index of an xts object.
## S3 method for class 'xts': index(x, ...) ## S3 method for class 'xts': index(x) <- value .index(x, ...) .index(x) <- value indexClass(x) indexClass(x) <- value indexFormat(x) indexFormat(x) <- value convertIndex(x,value)
x |
xts object |
value |
desired new class or format. See details |
... |
additional arguments (unused) |
The main accessor methods to an xts
object's index
is via the index
and index<-
replacement method.
The structure of the index internally is now a numeric
value corresponding to seconds since the epoch (POSIXct converted to numeric).
This change allows for near native-speed matrix subsetting, as
well as nearly instantaneous speed subsets by time.
A call to index
translates to the desired class on-the-fly.
The desired index class is stored as an attribute within the
xts object. Upon a standard index
call, this is used
to convert the numeric value to the desired class.
It is possible to view and set the class of the time-index
of a given xts
object via the indexClass
function.
To retrieve the raw numeric data a new accessor function (and replacement) has been
added .index
. This is primarily for internal use, but may be useful for
end-users.
The specified format must be a character string containing
one of the following: Date
, POSIXct
,
chron
, yearmon
, yearqtr
or timeDate
.
indexFormat
only manages the manner in which the object
is displayed via print
(also called automatically
when the object is returned) and in conversion to other
classes such as matrix
. The valid values
for indexFormat are the same for format
,
as this is the function that does the conversion internally.
convertIndex
returns a modified xts
object, and
does not alter the original.
Changing the index type may alter the behavior of xts functions expecting a different index, as well as the functionality of additional methods. Use with caution.
Jeffrey A. Ryan