[R] Moving standard deviation?
br44114 at yahoo.com
Mon Dec 13 21:26:46 CET 2004
A simple for loop does the job. Why not write your own function?
movsd <- function(series,lag)
movingsd <- vector(mode="numeric")
for (i in lag:length(series))
movingsd[i] <- sd(series[(i-lag+1):i])
This is very efficient: it takes (much) less time to write from
scratch than to look for an existing function.
From: doktora v
Sent: Monday, December 13, 2004 1:46 PM
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Moving standard deviation?
I have tried there but didn't find anything useful. Most of the
matches are for functions which take a std dev input, and the
part of the query relates to something else (like moving average in
the qcc package).
Anyway, it's not too difficult to create the function, but I was
wondering if anyone had done it before. Efficiency is a
I'll post what i come up with...
On Mon, 13 Dec 2004 10:04:59 -0800, Spencer Graves
<spencer.graves at pdf.com> wrote:
> A search for "moving standard deviation" at www.r-project.org
> search -> "R site search" just produced 7 matches. Please look at
> and let us know if none of those help you (and what you tried that
> didn't work).
> spencer graves
> doktora v wrote:
> >Is there a simple function in R to get a moving standard deviation
> >(i.e. for the last x samples)?
> >My goal is to plot bollinger bands around a moving average for
> >data. I use kernel smoothing for the moving average.
> >cheers and thanks!
> >over and out
> >-- doktora
> >R-help at stat.math.ethz.ch mailing list
> >PLEASE do read the posting guide!
> Spencer Graves, PhD, Senior Development Engineer
> O: (408)938-4420; mobile: (408)655-4567
R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!
Jazz up your holiday email with celebrity designs. Learn more.
More information about the R-help