[R] Relative subscripting

Gabor Grothendieck ggrothendieck at myway.com
Wed Dec 1 15:11:30 CET 2004


And, in general, using the right classes or data structures 
makes modelling your problem in R much easier.  It is 
surprising that there was an entire discussion on this
before Brian brought up the right approach.

Prof Brian Ripley <ripley <at> stats.ox.ac.uk> writes:

: 
: I've not seen anyone mention that this is really a time-series problem of 
: lagging variables, and something like
: 
: tmp <- ts.intersect(as.ts(return), lag(marketcap, -1))
: tmp[,1]*tmp[,2]
: 
: is a lot more intuitive, easier to generalize and keeps the timebase 
: information around.
: 
: On Wed, 1 Dec 2004 Ted.Harding <at> nessie.mcc.ac.uk wrote:
: 
: > On 01-Dec-04 Uwe Ligges wrote:
: >> (Ted Harding) wrote:
: >>> [...]
: >>> Let
: >>>
: >>>   N<-length(return)
: >>>   new.var <- return[2:N]*marketcap[1:(N-1)]
: >>
: >> Ted, I aggree to all of your points, but we can simplify by negative
: >> indices (and hence circumvent your note 1):
: >>   return[-1] * marketcap[-N]
: >>
: >> Uwe Ligges
: >
: > Neat footwork, Uwe!
: > (Why didn;t I think of that? No, don't answer ... )
: > Ted.




More information about the R-help mailing list