endpoints | R Documentation |

Extract index locations for an xts object that correspond to the *last*
observation in each period specified by `on`

and `k`

.

```
endpoints(x, on = "months", k = 1)
```

`x` |
An xts object. |

`on` |
A character string specifying the period. |

`k` |
The number of periods each endpoint should cover. |

`endpoints()`

returns a numeric vector that always begins with zero and ends
with the number of observations in `x`

.

Periods are always based on the distance from the UNIX epoch (midnight
1970-01-01 UTC), *not the first observation in x*. See the examples.

Valid values for the `on`

argument are: “us” (microseconds),
“microseconds”, “ms” (milliseconds), “milliseconds”,
“secs” (seconds), “seconds”, “mins” (minutes),
“minutes”, “hours”, “days”, “weeks”,
“months”, “quarters”, and “years”.

A numeric vector of beginning with 0 and ending with the number of
of observations in `x`

.

Jeffrey A. Ryan

```
data(sample_matrix)
endpoints(sample_matrix)
endpoints(sample_matrix, "weeks")
### example of how periods are based on the UNIX epoch,
### *not* the first observation of the data series
x <- xts(1:38, yearmon(seq(2018 - 1/12, 2021, 1/12)))
# endpoints for the end of every other year
ep <- endpoints(x, "years", k = 2)
# Dec-2017 is the end of the *first* year in the data. But when you start from
# Jan-1970 and use every second year end as your endpoints, the endpoints are
# always December of every odd year.
x[ep, ]
```

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.