Re: [R] applying a function recursively

2008-06-12 Thread Gabor Grothendieck
Wrap each element in an environment, flatten that and then extact the element in each environment. (Be sure not to use an old version of R since sufficiently far back R had a bug when environments were stored in lists that was since fixed.) L <- rapply(test.list, function(el) environment(), how =

Re: [R] applying a function recursively

2008-06-12 Thread Jim Lemon
Prof Brian Ripley wrote: > > See ?rapply Golly, the things one learns when least expecting it. Jim __ R-help@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-guid

Re: [R] applying a function recursively

2008-06-12 Thread Georg Otto
Hi, thanks a lot for your help. Somehow rapply had escaped my notice. I also have a follow-up question on that. I would like to "flatten" my output list to a list with only one level. Option "unlist" in rapply returns a character vector, in my example: > rapply(test.list, rev, how="unlist")

Re: [R] applying a function recursively

2008-06-12 Thread Jim Lemon
Georg Otto wrote: Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: ... I understand that with a fixed number of recursion levels one can use lapply() in a nested way, but what i

Re: [R] applying a function recursively

2008-06-11 Thread Marc Schwartz
on 06/11/2008 10:51 AM Georg Otto wrote: Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), "C"=c("g", "h", "i"

Re: [R] applying a function recursively

2008-06-11 Thread Charles C. Berry
See ?rapply for your example rapply( test.list, rev, how='replace' ) HTH, Chuck On Wed, 11 Jun 2008, Georg Otto wrote: Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of

Re: [R] applying a function recursively

2008-06-11 Thread Prof Brian Ripley
See ?rapply On Wed, 11 Jun 2008, Georg Otto wrote: Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), "C"=c("

[R] applying a function recursively

2008-06-11 Thread Georg Otto
Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: > test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), > "C"=c("g", "h", "i")), + "II"=list("A"=lis