[R] Simple for-loop runs out of memory

Astrix ast_rix85 at hotmail.com
Tue Mar 16 23:51:35 CET 2010


I have the following simple for-loop, which makes R crash every time. The
length of the vectors is about 1200 rows, 1 column.

n = max(length(GSPC),length(FTSE))

for(i in 1:1000)
{
	if (row.names(GSPC)[i]==row.names(FTSE)[i]){
	} else {
		if (row.names(GSPC)[i]>row.names(FTSE)[i]){	
		GSPC<-rbind(GSPC[1:(i-1),],GSPC[(i-1):length(GSPC),])
		row.names(GSPC)[i]=row.names(FTSE)[i]
		} else {
		FTSE<-rbind(FTSE[1:(i-1),],FTSE[(i-1):length(FTSE),])
		row.names(FTSE)[i]=row.names(GSPC)[i]
		}
	}

}

I have no idea why it crashes, it should be a very simple task of running
through the 1200 entries. The if loop is called only about 10 times during
the entire loop.
What could be the problem?
-- 
View this message in context: http://n4.nabble.com/Simple-for-loop-runs-out-of-memory-tp1595698p1595698.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list