window.xts | R Documentation |

Method for extracting time windows from xts objects.

```
## S3 method for class 'xts'
window(x, index. = NULL, start = NULL, end = NULL, ...)
```

`x` |
An xts object. |

`index.` |
A user defined time index (default |

`start` |
A start time coercible to POSIXct. |

`end` |
An end time coercible to POSIXct. |

`...` |
Unused. |

The xts `window()`

method provides an efficient way to subset an xts object
between a start and end date using a binary search algorithm. Specifically,
it converts `start`

and `end`

to POSIXct and then does a binary search of
the index to quickly return a subset of `x`

between `start`

and `end`

.

Both `start`

and `end`

may be any class that is convertible to POSIXct, such
as a character string in the format ‘yyyy-mm-dd’. When `start = NULL`

the returned subset will begin at the first value of `index.`

. When
`end = NULL`

the returned subset will end with the last value of `index.`

.
Otherwise the subset will contain all timestamps where `index.`

is between
`start`

and `end`

, inclusive.

When `index.`

is specified, `findInterval()`

is used to quickly retrieve
large sets of sorted timestamps. For the best performance, `index.`

must be
a *sorted* POSIXct vector or a numeric vector of seconds since the epoch.
`index.`

is typically a subset of the timestamps in `x`

.

The subset of `x`

that matches the time window.

Corwin Joy

`subset.xts()`

, `findInterval()`

, `xts()`

```
## 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
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.