movingDiff: Moving Differences

View source: R/movingDiff.R

movingDiffR Documentation

Moving Differences

Description

Filter a regular series of data to compute a moving difference.

Usage

movingDiff(x, span = 1, pos = "end")

Arguments

x

the data to be averaged or differenced. Missing values are permitted but result in missing values in the output.

span

the span of the differences.

pos

how to position the output data relative to the value returned; "center" means that value represents the difference between the preceding span/2 value and the following span/2 value, "end" or "trailing" means that value is the difference between the preceding span value and the current value, and "begin" or "leading" means that value is the difference between the current value and the following span value.

Value

A vector of the same length as x containing the differences.

See Also

filter, diff, movingAve

Examples


# Construct a simple valley
movingData <- abs(seq(-5, 5))
movingDiff(movingData, span=1)
# Compare to diff:
diff(movingData)

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.