ShiftInTime: ShiftInTime

ShiftInTimeR Documentation

ShiftInTime

Description

Shift a time-series vector forward or backward.

Usage

ShiftInTime(.X, .rate = 1, .shift = 0, .smooth = 0, .mod = NA)

Arguments

.X

A numeric vector, usually representing a measurement history.

.rate

The data rate in Hz (default 1 Hz).

.shift

The shift to be applied, in milliseconds. Can be positive or negative. A negative value moves the time series earlier in time, as would be needed to correct for a delay in recording.

.smooth

The smoothing interval in milliseconds. Controls smoothing of the time series after interpolation to high rate but before discrete points are selected from that series to represent the shifted series. .smooth may be either zero or a positive odd integer. Default is 0, in which case no smoothing is performed. This is also the case for smoothing intervals less than 40 ms (or five samples at 125-Hz). If .smooth is larger than 40, smoothing is performed using 3rd-order Savitzky-Golay polynomials spanning that interval.

.mod

For variables that wrap around to zero at some modulus, like an angle variable such as heading at modulus 360, this specifies that modulus. It is used to avoid interpolation to intermediate values between 0 and .mod in such cases. The default is NA, so omitting this parameter will inhibit the special action needed for variables with a modulus.

Details

For a vector assumed to be a time series with sampling rate .rate, shift by .shift milliseconds. Fractional shifts are handled by interpolating to a 125-Hz sequence, then picking values from that interpolated sequence after shifting. The shift adds duplicate values at one end and removes values from the other end. The .smooth logical variable gives some optional smoothing of the interpolated series before subsetting to the original rate. The result is the shifted time series.

Value

The same series after shifting in time, possibly by fractions of the sampling period.

Author(s)

William Cooper

Examples

THDG2 <- ShiftInTime (RAFdata$THDG, .shift=-60)
newVariable <- ShiftInTime (1:50, .rate=1, .shift=-500)

NCAR/Ranadu documentation built on Jan. 27, 2023, 1:09 a.m.