picking up the current index plus n -1, n-2, ..., n-20
Hi Stephen, If you want to calculate moving averages, take a look at the TTR package. For applying any function over a rolling time window, see rollapply in the zoo package. R-help is a better venue if you simply want to understand how to do it will apply, since it's not strictly finance-related. Best, -- Joshua Ulrich ?| ?FOSS Trading: www.fosstrading.com On Wed, Nov 10, 2010 at 9:28 PM, Stephen Choularton
<stephen at organicfoodmarkets.com.au> wrote:
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
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.