Apply a loop containing a function on a list

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Apply a loop containing a function on a list

ali_protocol
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.
Reply | Threaded
Open this post in threaded view
|

Re: Apply a loop containing a function on a list

Milan Bouchet-Valat
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Apply a loop containing a function on a list

jholtman
In reply to this post by ali_protocol
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
<[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.