endpoints | R Documentation |

Extract index locations for an `xts`

object that correspond to the
*last* observation in each period specified by `on`

.

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

`x` |
an xts object |

`on` |
the periods endpoints to find as a character string |

`k` |
along every k-th element - see notes |

`endpoints`

returns a numeric vector corresponding to the *last*
observation in each period. The vector always begins with zero and ends with
the last observation in `x`

.

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

Valid values for the argument `on`

include: “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 value equal to the
number of observations in the `x`

argument.

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, ]
```

xts documentation built on April 17, 2023, 1:07 a.m.

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.