diffit | R Documentation |
Calculate the row differences of a numeric or Boolean vector, matrix, or xts time series.
diffit(input, lagg = 1, ...)
input |
A numeric or Boolean vector or matrix, or xts time series. |
lagg |
An integer equal to the number of time periods of lag
(default is |
The function diffit()
calculates the row differences between
rows that are lagg
rows apart. Positive lagg
means that the
difference is calculated as the current row minus the row that is
lagg
rows above. (vice versa for a negative lagg
). This also
applies to vectors, since they can be viewed as single-column matrices. The
leading or trailing stub periods are padded with zeros.
When applied to xts time series, the function diffit()
calls
the function diff.xts()
from package
xts, but it
pads the output with zeros instead of with NA
s.
A vector, matrix, or xts time series. with the same dimensions as the input object.
# Diff vector by 2 periods
rutils::diffit(1:10, lagg=2)
# Diff matrix by negative 2 periods
rutils::diffit(matrix(1:10, ncol=2), lagg=-2)
# Diff an xts time series
rutils::diffit(rutils::etfenv$VTI, lagg=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.