[R] any way to make the code more efficient ?

Leeds, Mark (IED) Mark.Leeds at morganstanley.com
Fri Dec 8 22:16:49 CET 2006


The code bekow works so this is why I didn't include the data to
reproduce it. The  loops about 500
times and each time, a zoo object with 1400 rows and 4 columns gets
created. ( the rows represent minutes so each file is one day 
worth of data). Inside the loop, I keep rbinding the newly created zoo
object to the current zoo object so that it gets bigger and 
bigger over time.

Eventually, the new zoo object, fullaggfxdata,  containing all the days
of data is created.

I was just wondering if there is a more efficient way of doing this. I
do know the number of times the loop will be done at the beginning so
maybe creating the a matrix or data frame at the beginning and putting
the daily ones in something like that would
Make it be faster. But, the proboem with this is I eventually do need a
zoo object.  I ask this question because at around the 250
mark of the loop, things start to slow down significiantly and I think I
remember reading somewhere that doing an rbind of something to itself is
not a good idea.  Thanks. 

#=======================================================================
===============================================

start<-1

for (filecounter in (1:length(datafilenames))) { 

print(paste("File Counter = ", filecounter))
datafile= paste(datadir,"/",datafilenames[filecounter],sep="")
aggfxdata<-clnaggcompcurrencyfile(fxfile=datafile,aggminutes=aggminutes,
fillholes=1)
logbidask<-log(aggfxdata[,"bidask"]) 
aggfxdata<-cbind(aggfxdata,logbidask)

if ( start == 1 ) {
fullaggfxdata<-aggfxdata
start<-0
} else {
fullaggfxdata<-rbind(fullaggfxdata,aggfxdata)
}


}

#=======================================================================
==================================
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}




More information about the R-help mailing list