foldrange: Successively apply a function to a rolling range of a...

Description Arguments Value Usage Details Author(s) See Also Examples

Description

Apply a function to a rolling range of a sequence and the accumulated value of the previous function applications

Arguments

x

Any indexable data structure

window

The length of the sub-sequence passed to fn

fn

The function applied to the rolling range

acc

An object that stores the intermediate accumulated result

Value

The accumulated result

Usage

foldrange(x, window, fn, acc, idx) foldrange(x, window, fn, acc, 0) foldrange(x, window, fn, acc=0, idx=length(x)-window+1)

When ! is.null(dim(x)) foldrange(x, window, fn, acc=0)

Details

This function is the fold counterpart of maprange. It's primarily here for completeness purposes, as the utility of this function is still to be determined.

Author(s)

Brian Lee Yung Rowe

See Also

map fold foldblock

Examples

1
2
3
4
5
6
## Not run: 
# Mean of rolling means
z <- sapply(1:500, 
  function(x) foldrange(rnorm(50), 10, function(a,b) mean(a) + b) / 41)

## End(Not run)

lambda.tools documentation built on May 2, 2019, 4:28 a.m.