[R-sig-finance] How can I do this better? (Filling in last traded
price for NA)
Ajay Shah
ajayshah at mayin.org
Sun Sep 12 17:33:36 CEST 2004
I have 3 different daily time-series. Using union() in the "its"
package, I can make a long matrix, where rows are created when even
one of the three time-series is observed:
massive <- union(nifty.its, union(inrusd.its, infosys.its))
Now in this, I want to replace NA values for prices by the
most-recently observed price. I can do this painfully --
for (i in 2:nrow(massive)) {
for (j in 1:3) {
if (is.na(massive[i,j])) {
massive[i,j] = massive[i-1,j]
}
}
}
But this is horribly slow. Is there a more clever way?
--
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
More information about the R-sig-finance
mailing list