Extract time windows from an xts series
Method for extracting time windows from xts
objects.
## S3 method for class 'xts' window(x, index. = NULL, start = NULL, end = NULL, ...)
x |
an object. |
index. |
a user defined time index. This defaults to the |
start |
a start time. Extract |
end |
an end time. Extract |
... |
currently not used. |
The point of having window
in addition to the regular subset function
is to have a fast way of extracting time ranges from an xts
series. In
particular, this method will convert start
and end
to
POSIXct
then do a binary lookup on the internal xts
index to
quickly return a range of matching dates. With a user supplied index.
,
a similarly fast invocation of findInterval
is used so that large sets
of sorted dates can be retrieved quickly.
The matching time window is extracted.
Corwin Joy
## xts example x.date <- as.Date(paste(2003, rep(1:4, 4:1), seq(1,19,2), sep = "-")) x <- xts(matrix(rnorm(20), ncol = 2), x.date) x window(x, start = "2003-02-01", end = "2003-03-01") window(x, start = as.Date("2003-02-01"), end = as.Date("2003-03-01")) window(x, index = x.date[1:6], start = as.Date("2003-02-01")) window(x, index = x.date[c(4, 8, 10)]) ## Assign to subset window(x, index = x.date[c(4, 8, 10)]) <- matrix(1:6, ncol = 2) x
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.