[R-SIG-Finance] picking up the current index plus n -1, n-2, ..., n-20

Stephen Choularton stephen at organicfoodmarkets.com.au
Thu Nov 11 04:28:02 CET 2010


Hi

I am trying to use

apply(X=x,MARGIN=1,FUN=myFunction)

to pick up and calculate moving averages and the like.

I can get this type of thing to work:

myFunction <- function (x){return( 2 * x)}

but of course that only work on one index at a time when I want to do 
something like this:

myFunction <- function (x){return( sum(x[n,]:x[n-20]))}

but of course it doesn't work.

I am still looking in R in a Nutshell but I just wondered if someone 
could put me out of my misery.

-- 
Stephen Choularton Ph.D., FIoD



More information about the R-SIG-Finance mailing list