[R] for() to lapply()

About this list Date view Thread view Subject view Author view Attachment view

From: Kenneth Cabrera (krcabrer@perseus.unalmed.edu.co)
Date: Fri 21 May 2004 - 06:52:22 EST


Message-id: <opr8bf9kd8faouaq@200.24.8.4>

Hi dear R-users:

I have the following problem:
I have a list of data.frames (12 variables and 60000 rows, each)

I have to merge from an specific point of the list to the
end of the list, I am doing so with a for() loop but it is
too inefficient and it exhausts memory.

How can I convert this for() loop in a function and then use
lapply?
-------------------------------------------------------------
LIST: list of data frames.
m:point of start merging.

result<-merge(LIST[[m]],LIST[[m+1]],by="key",all.x=T)
for (i in (m+2):length(LIST))
{
   result<-merge(result,LIST[[i]],by="key",all.x=T)
}

The problem is the acumulative: "result<-merge(result,...)"

I can think in a function like this:

mergeListelem<-function(i,LS,m)
{
  merge(LS[[m]],LS[[i]],by="key",all.x=T)
}

ind<-m:length(LIST)
lapply(ind,mergeListelem,LIST,m)

But I just obtain a list of merged data.frames,
and I don´t know how to join all the elements
of the list in just one final data.frame.

Thank you for your help

-- 
Kenneth Cabrera
Universidad Nacional de Colombia
Tel Of 430 9351
Cel 315 504 9339
Medellín

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:11 EST