Skip to content
Prev 60161 / 398502 Next

Relative subscripting

wouldn't it be return[2:NROW(return)]*marketcap[1:(NROW(return)-1)]

(note that return is also a function in R so maybe you should stay away
from calling your variable return. Anyways if you have a data frame you
can add another variable to it but attach an NA to the first element
(since you are lagging variables) i.e.

mydata$myvar<-c(NA, mydata$return[2:nrow(mydata)]*mydata$marketcap[1:(nrow(mydata)-1)]


Jean
On Tue, 30 Nov 2004, Tobias Muhlhofer wrote: