Hi all, I want to do this: B.list$aa= (a loop containing My.fun acting on the reults of second function on a A.list$aa)) or, overally B.list$aa = function (A.list$aa) B.list and A.list has many sublists aa, ab and.... Is there a way I can apply the function and loop on all sublists of A.list and get B.list? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Apply-a-loop-containing-a-function-on-a-list-tp4471188p4471188.html Sent from the R help mailing list archive at Nabble.com.
Milan Bouchet-Valat
2012-Mar-14 11:03 UTC
[R] Apply a loop containing a function on a list
Le mercredi 14 mars 2012 ? 00:51 -0700, ali_protocol a ?crit :> Hi all, > I want to do this: > > B.list$aa= (a loop containing My.fun acting on the reults of second > function on a A.list$aa)) > or, overally > B.list$aa = function (A.list$aa) > B.list and A.list has many sublists aa, ab and.... Is there a way I can > apply the function and loop on all sublists of A.list and get B.list?Please provide a small example, you can easily create two lists to illustrate your point. It's hard to help without that, it would require us mocking up an example for you, and we might get it wrong. Cheers
Without a subset of data, it is hard to come up with a solution. Now here is a way of determining what names are in common and then maybe doing something: B.names <- names(B.list) A.names <- names(A.list) common <- intersect(B.names, A.names) for (i in common){ B.list[[i]] <- function(A.list[[i]]) } On Wed, Mar 14, 2012 at 3:51 AM, ali_protocol <mohammadianalimohammadian at gmail.com> wrote:> Hi all, > I want to do this: > > ? ? ? ?B.list$aa= (a loop containing My.fun acting on the reults of second > function on a A.list$aa)) > or, overally > ? ? ? ?B.list$aa = function (A.list$aa) > B.list and A.list has many sublists aa, ab and.... Is there a way I can > apply the function and loop on all sublists of A.list and get B.list? > > > Thanks in advance. > > -- > View this message in context: http://r.789695.n4.nabble.com/Apply-a-loop-containing-a-function-on-a-list-tp4471188p4471188.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.