Subset an xts time series (extract an xts sub-series corresponding to the input dates).
An xts time series.
The start date of the extracted time series data.
The end date of the extracted time series data, or the number of data rows to be extracted.
A Boolean argument: if
sub_set() extracts an xts sub-series
corresponding to the input dates. If
end_date is a date object or
a character string representing a date, then
standard bracket subsetting using the package
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
end_date 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
end_date 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.
end_date is a number, and either
end_date are outside the date range of
sub_set() extracts the maximum available range of
An xts time series with the same number of columns as the input time series.
1 2 3 4 5 6 7 8
# Subset an xts time series using two dates rutils::sub_set(rutils::etf_env$VTI, start_date="2015-01-01", end_date="2015-01-10") # Extract 6 consecutive rows of data from the past, using a date and a negative number rutils::sub_set(rutils::etf_env$VTI, start_date="2015-01-01", end_date=-6) # Extract 6 calendar days of data rutils::sub_set(rutils::etf_env$VTI, start_date="2015-01-01", end_date=6, get_rows=FALSE) # Extract up to 100 consecutive rows of data rutils::sub_set(rutils::etf_env$VTI, start_date="2016-08-01", end_date=100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.