roll.recycle: Rolling Window that Recycles

Description Usage Arguments Details See Also Examples

View source: R/roll.recycle.R

Description

A rolling window that will recycle the elements at the start of the vector when the window extends past the end of the vector (and will keep looping through until output of desired length is achieved)

Usage

1
roll.recycle(vec, size, n, by = 1, index = FALSE)

Arguments

vec

vector upon which to perform the rolling window

size

integer length of the rolling window

n

integer indicating the total number of windows to apply

by

integer specifying how far the window should advance between applications

index

logical, FALSE (default) returns the elements of vec subset by the window, TRUE returns the integers specifying the indices of vec in each window

Details

The idea is to apply a rolling window to a sequence of values that are arranged circularly but are represented by a linear vector. Can be used for generating permutations that retain the original arrangement of its elements (when size==length(vec) & size==n). Can also reproduce the output of diag, although in this case roll.recycle is a little more than twice as slow, so when producing a matrix in which all non-diagonal elements are 0, just use diag. Was created to fill a matrix with a few values in a way that recycled the values within a column (if needed) and induced a frame shift across columns; the result was used in statistical simulations of time series.

See Also

See rbLib-package for package overview.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Rolling window around a circle
roll.recycle(seq(20,360,by=20), 10, 10, by=2)

# Can create identity matrix
# Note that size and by
# can be interpreted as nrow and ncol
diag(1,10,6)
roll.recycle(c(1,rep(0,9)),10,6,-1)

# Recycle and shift position of parameters
params <- seq(0,1, by=0.25)
ts.length <- 20
n.sims <- 5
roll.recycle(params, ts.length, n.sims) 

rBatt/rbLib documentation built on May 26, 2019, 7:45 p.m.