Skip to content

apply moving window function on a quasi circular vector

Notifications You must be signed in to change notification settings

Davidatlarge/circle_apply

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

circle_apply

Description

This is a wrapper for zoo::rollapply() allowing to fill the resulting leading and tailing NAs by circling the vector back on itself. Apply a function to a vector and fill the ends by circling the vector so that the last values proceed the head and the first values follow the tail. Useful to smooth vectors that can be regarded as repetitive, e.g. daily climatologies.

Arguments

values – vector of values

n – size of the rolling window (passed to width argument of zoo::rollapply)

fun – function to apply (passed to FUN argument of zoo::rollapply), defaults to “mean”

Example

set.seed(200)
v <- rnorm(12, 2, 2)
r <- zoo::rollapply(v, 5, mean, fill=NA)
s <- circle_apply(v, n = 5)
plot(v)
points(r, col="blue")
points(s, col="red", pch="x")

About

apply moving window function on a quasi circular vector

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages