[R] How to do a moving window on standard deviation
Ray Brownrigg
Ray.Brownrigg at ecs.vuw.ac.nz
Sun Jan 30 23:09:38 CET 2011
On Mon, 31 Jan 2011, eric wrote:
> I'd rather do this without getting into zoo objects at the moment. OK, how
> about with a simple loop ? Why doesn't this work ?
>
> attach(xyz)
> j <- for(i in 4: length(Close)) sd(Close[i]:Close[(i-3)])
To answer your question, it is because the value returned from a loop is the last value
calculated, not every value calculated.
HTH,
Ray Brownrigg
More information about the R-help
mailing list