Description Usage Arguments Details Author(s) Examples
Generic functions to extract, replace, and format the class of the index of an xts object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ## S3 method for class 'xts'
index(x, ...)
## S3 replacement method for class 'xts'
index(x) <- value
.index(x, ...)
.index(x) <- value
indexClass(x)
indexClass(x) <- value
tclass(x)
tclass(x) <- value
indexFormat(x)
indexFormat(x) <- value
convertIndex(x,value)
# time component extraction/conversion
.indexDate(x)
.indexday(x)
.indexmday(x)
.indexwday(x)
.indexweek(x)
.indexmon(x)
.indexyday(x)
.indexyear(x)
.indexhour(x)
.indexmin(x)
.indexsec(x)
|
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.
.indexXXX
functions are useful to extract time
components of the underlying time index. The ‘indexClass’
is virtual, and as such suitable conversions are made depending
on the component requested.
The specified value for
indexClass<-
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.POSIXct
,
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
1 2 3 4 5 6 7 8 9 10 | x <- timeBasedSeq('2010-01-01/2010-01-02 12:00')
x <- xts(1:length(x), x)
# all obs. in the first 6 and last 3 minutes of the
# 8th and 15th hours on each day
x[.indexhour(x) %in% c(8,15) & .indexmin(x) %in% c(0:5,57:59)]
# change the index format
indexFormat(x) <- "%Y-%b-%d %H:%M:%OS3"
head(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.