sub_set | R Documentation |
Subset an xts time series (extract an xts sub-series corresponding to the input dates).
sub_set(xtsv, startd, endd, get_rows = TRUE)
xtsv |
An xts time series. |
startd |
The start date of the extracted time series data. |
endd |
The end date of the extracted time series data, or the number of data rows to be extracted. |
get_rows |
A Boolean argument: if |
The function sub_set()
extracts an xts sub-series
corresponding to the input dates. If endd
is a date object or
a character string representing a date, then sub_set()
performs
standard bracket subsetting using the package
xts.
The rows of data don't necessarily correspond to consecutive calendar days
because of weekends and holidays. For example, 10 consecutive rows of data
may correspond to 12 calendar days. So if endd
is a number, then
we must choose to extract either the given number of rows of data
(get_rows=TRUE
) or the given number of calendar days
(get_rows=FALSE
).
If endd
is a positive number then sub_set()
returns the
specified number of data rows from the future, and if it's negative then it
returns the data rows from the past.
If endd
is a number, and either startd
or
endd
are outside the date range of xtsv
, then
sub_set()
extracts the maximum available range of xtsv
.
An xts time series with the same number of columns as the input time series.
# Subset an xts time series using two dates
rutils::sub_set(rutils::etfenv$VTI, startd="2015-01-01", endd="2015-01-10")
# Extract 6 consecutive rows of data from the past, using a date and a negative number
rutils::sub_set(rutils::etfenv$VTI, startd="2015-01-01", endd=-6)
# Extract 6 calendar days of data
rutils::sub_set(rutils::etfenv$VTI, startd="2015-01-01", endd=6, get_rows=FALSE)
# Extract up to 100 consecutive rows of data
rutils::sub_set(rutils::etfenv$VTI, startd="2016-08-01", endd=100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.