Skip to contents

Apply a simple moving average smoothing filter to vector data

Usage

filter_moving_average(
  x,
  t = seq_along(x),
  width = NULL,
  span = NULL,
  verbose = TRUE
)

Arguments

x

A numeric vector.

t

An optional numeric vector of time or sample number.

width

An integer value defining the number of samples centred on idx over which the operation will be performed.

span

A numeric value in units of time_channel defining the timespan centred on idx over which the operation will be performed.

verbose

A logical to return (the default) or silence warnings and messages which can be used for data error checking. Abort errors will always be returned.

Value

A numeric vector the same length as x.

Details

Applies a centred (symmetrical) moving average filter in a local window defined by either width as the number of samples around idx between [idx - floor(width/2), idx + floor(width/2)]. Or by span as the timespan in units of time_channel between [t - span/2, t + span/2].

If there are no valid values within the calculation window, will return NA. A partial moving average will be calculated at the edges of the data.

See also