[R] Running out of memory when using lapply

Kamila Naxerova kamila.naxerova at childrens.harvard.edu
Mon Aug 7 17:17:58 CEST 2006


Hi all!

I'm afraid I programmed something totally non-sensical and inefficient, 
but I can't figure out how to do it better.

I have a list of ~ 40 000 characters. I want to take each element at a 
time, map it to a large data frame with 
hit=which(data.frame$column==elementFromList), then compute some 
statistic on data.frame[hit,] and return a result that consists of 
either 1) a list of integers or 2) a character.

res=lapply(listof40000,myfunction,dataframeToSearchIn)

On a small scale, this works and returns something like

str(res)
[[1]]
[1] "UNIQUE"
[[2]]
[1]   405   406   407 16351
[[3]]
[1] "REMOVE"
[[4]]
[1] "REMOVE"

If I try this with the entire 40 000 character list, though, I get the 
"Reached total allocation of 1022Mb: see help(memory.size)" error message.

Can someone please give me a hint how to solve this problem correctly? 
THANKS!

Kamila



More information about the R-help mailing list