ediff: Lagged Differences with equal length

View source: R/ediff.R

ediffR Documentation

Lagged Differences with equal length

Description

Often when creating lagged differences, it is awkward that the differences vector is shorter than the original. ediff pads with pad.value to make its output the same length as the input.

Usage

ediff(
  x,
  lag = 1,
  differences = 1,
  pad = c("head", "tail", "symmetric"),
  pad.value = NA,
  frontPad,
  ...
)

Arguments

x

a numeric vector or a matrix containing the values to be differenced

lag

an integer indicating which lag to use

differences

an integer indicating the order of the difference

pad

one of "head", "tail", or "symmetric". indicating where the pad.value padding should be added to the result.

pad.value

the value to be used for padding.

frontPad

logical indicating whether padding is on the front (head) or back (tail) end. This exists for backward compatibility. New code should use pad instead.

...

further arguments to be passed to or from methods

See Also

diff() since ediff is a thin wrapper around diff().

Examples

ediff(1:10)
ediff(1:10, pad.value = 0)
ediff(1:10, 2)
ediff(1:10, 2, 2)
x <- cumsum(cumsum(1:10))
ediff(x, lag = 2)
ediff(x, differences = 2)
ediff(x, differences = 2, pad = "symmetric")
ediff(.leap.seconds)

mosaicCore documentation built on Nov. 5, 2023, 9:06 a.m.