[R-SIG-Finance] picking up the current index plus n -1, n-2, ..., n-20
Santosh Srinivas
santosh.srinivas at gmail.com
Thu Nov 11 04:52:56 CET 2010
Hi Stephen,
Can't understand your question without a dataset (see dput) and reproducible
sample
But not sure why sum(x[n:(n-20),]) would not work (see ?unlist too for
possible solutions... from experience)
HTH
-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Stephen
Choularton
Sent: 11 November 2010 08:58
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-SIG-Finance] picking up the current index plus n -1, n-2, ...,
n-20
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.
More information about the R-SIG-Finance
mailing list