shift | R Documentation |
Apply a temporal shift to a time series object. This function shifts the values in time while preserving the structure of the object. Common uses include:
Aligning regressors with different temporal offsets
Applying temporal derivatives to time series
Correcting for timing differences between signals
shift(x, ...)
x |
An object representing a time series or a time-based data structure |
... |
Additional arguments passed to methods. Common arguments include:
|
An object of the same class as the input, with values shifted in time:
Values are moved by the specified offset
Object structure and dimensions are preserved
Empty regions are filled with padding value
regressor()
, evaluate()
# Create a simple time series with events
event_data <- data.frame(
onsets = c(1, 10, 20, 30),
run = c(1, 1, 1, 1)
)
# Create sampling frame
sframe <- sampling_frame(blocklens = 50, TR = 2)
# Create regressor from events
reg <- regressor(
onsets = event_data$onsets,
sampling_frame = sframe
)
# Shift regressor forward by 2 seconds
reg_forward <- shift(reg, offset = 2)
# Shift regressor backward by 1 second
reg_backward <- shift(reg, offset = -1)
# Evaluate original and shifted regressors
times <- seq(0, 50, by = 2)
orig_values <- evaluate(reg, times)
shifted_values <- evaluate(reg_forward, times)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.