calc_endpoints | R Documentation |
Calculate a vector of equally spaced end points along the elements of a vector, matrix, or time series.
calc_endpoints(xtsv, interval, stub_front = TRUE)
xtsv |
A vector, matrix, or time series. |
interval |
The number of elements between neighboring end points. or a string representing a time period (minutes, hours, days, etc.) |
stub_front |
A Boolean argument: if |
The end points are a vector of integers which divide the elements
(rows) of xtsv
into equally spaced intervals.
If interval
is an integer then calc_endpoints()
calculates the number of whole intervals that fit over the elements (rows)
of xtsv
.
If a whole number of intervals doesn't fit over the elements (rows) of
xtsv
, then calc_endpoints()
adds a stub interval either at
the beginning (the default) or at the end.
If interval
is a string representing a time period (minutes,
hours, days, etc.), then calc_endpoints()
simply calls the function
endpoints()
from package
xts.
The function calc_endpoints()
is a generalization of function
endpoints()
from package
xts, since
interval
can accept both integer and string values.
Similar to xts::endpoints()
, the first integer returned by
calc_endpoints()
is equal to zero.
An integer vector of equally spaced end points (vector of integers).
# Calculate end points with initial stub interval
rutils::calc_endpoints(1:100, interval=11)
# Calculate end points with a stub interval at the end
rutils::calc_endpoints(rutils::etfenv$VTI, interval=365, stub_front=FALSE)
# Calculate end points at the end of every hour
rutils::calc_endpoints(rutils::etfenv$VTI, interval="hours")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.