-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
indexClass.Rd
128 lines (107 loc) · 3.42 KB
/
indexClass.Rd
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
\name{indexClass}
\alias{indexClass}
\alias{tclass}
\alias{indexFormat}
\alias{convertIndex}
\alias{indexClass<-}
\alias{tclass<-}
\alias{indexFormat<-}
\alias{index.xts}
\alias{index<-.xts}
\alias{.indexhour}
\alias{.indexsec}
\alias{.indexmin}
\alias{.indexyear}
\alias{.indexymon}
\alias{.indexyday}
\alias{.indexday}
\alias{.indexDate}
\alias{.indexmday}
\alias{.indexwday}
\alias{.indexweek}
\alias{.indexmon}
\alias{.index}
\alias{.index<-}
\title{ Extracting/Replacing the Class of an xts Index }
\description{
Generic functions to extract, replace, and format the class of the index
of an xts object.
}
\usage{
\method{index}{xts}(x, ...)
\method{index}{xts}(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)
}
\arguments{
\item{x}{ xts object }
\item{value}{ desired new class or format. See details }
\item{\dots}{ additional arguments (unused) }
}
\details{
The main accessor methods to an \code{xts} object's index
is via the \code{index} and \code{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 \code{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 \code{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 \code{xts} object via the \code{indexClass} function.
To retrieve the raw numeric data a new accessor function (and replacement) has been
added \code{.index}. This is primarily for internal use, but may be useful for
end-users.
\code{.indexXXX} functions are useful to extract time
components of the underlying time index. The \sQuote{indexClass}
is virtual, and as such suitable conversions are made depending
on the component requested.
The specified value for
\code{indexClass<-} must be a character string containing
one of the following: \code{Date}, \code{POSIXct},
\code{chron}, \code{yearmon}, \code{yearqtr} or \code{timeDate}.
\code{indexFormat} only manages the manner in which the object
is displayed via \code{print} (also called automatically
when the object is returned) and in conversion to other
classes such as \code{matrix}. The valid values
for indexFormat are the same for \code{format.POSIXct},
as this is the function that does the conversion internally.
\code{convertIndex} returns a modified \code{xts} object, and
does \emph{not} alter the original.
Changing the index type may alter the behavior of \pkg{xts}
functions expecting a different index, as well as the functionality
of additional methods. Use with caution.
}
\author{ Jeffrey A. Ryan }
\examples{
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)
}
\keyword{ utilities }