windowApply: Apply a function to one variable on each sliding window of...

Description Usage Arguments Value Note Author(s)

View source: R/windowApply.R

Description

Given a set of (x,y) pairs with x in non-decreasing order, apply a function to each maximal set of consecutive pairs where the range of x values is at most a fixed value w, the window size. For example, if x is time, y is temperature, w is 30 and the function is mean, calculate the mean temperature over a sliding window of width 30 seconds.

Usage

1
windowApply(x, y, w, f)

Arguments

x

- vector of values in non-decreasing order

y

- vector of arbitrary values, with length(x)==length(y)

w

- width of sliding window in same units as x

f

- function of one or two variables to apply to each sliding window of values. f is called on each window of data, with windowed y values if f accepts one argument and windowed x and y values if f takes two arguments.

Value

result of applying f to a sliding window of y values; this has the same length as x and y. The ith element is obtained by applying f to y[i:j] where j is the largest index such that j <= length(x) and x[j]-x[i] < w

Note

The number of elements of y used to compute each element in the result will not in general be constant. It will be constant if the values of x are equally spaced, except that the tail end of the result will be computed with fewer elements.

Author(s)

John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm


jbrzusto/sensorgnome-R-package documentation built on May 18, 2019, 9:19 p.m.