Re: [R] Extracting elements out of list in list in list

2015-01-19 Thread Chel Hee Lee
Aha! I haven't thought about it. I really like the approach presented by Bert Gunter in the previous post. It is a good lesson. I made my previous code a little bit better by building a function that pulls out only the desired component. At this time, the names of sublists are changed as

Re: [R] Extracting elements out of list in list in list

2015-01-19 Thread Rainer M Krug
Bert Gunter gunter.ber...@gene.com writes: Chee Hee's approach is both simpler and almost surely more efficient, I am not sure about the efficient - if the lists are large, they need to be copied and un-listed which both require memory allocations and processing time - so I would actually guess

Re: [R] Extracting elements out of list in list in list

2015-01-19 Thread Rainer M Krug
Chel Hee Lee chl...@mail.usask.ca writes: This approach may not be fancy as what you are looking for. As long as it works ans=d it is efficient, it is OK. xl - unlist(x) The unlist might be a problem as I am working with quite large lists. xl[grep(A, names(xl))] The grep has one problem,

Re: [R] Extracting elements out of list in list in list

2015-01-19 Thread Rainer M Krug
Brian Diggs brian.s.di...@gmail.com writes: On 1/16/15 9:34 AM, Bert Gunter wrote: Chee Hee's approach is both simpler and almost surely more efficient, but I wanted to show another that walks the tree (i.e. the list) directly using recursion at the R level to pull out the desired

Re: [R] Extracting elements out of list in list in list

2015-01-19 Thread Dénes Tóth
Hi, Here is a solution which is restricted to lists with identically shaped branches (like your example). The idea is to transform the list to an array and make use of the fact that unlist(x, use.names=FALSE) is much much faster for large lists than unlist(x). # function which transforms a

[R] Extracting elements out of list in list in list

2015-01-16 Thread Rainer M Krug
Hi Consider the following variable: --8---cut here---start-8--- x1 - list( A = 11, B = 21, C = 31 ) x2 - list( A = 12, B = 22, C = 32 ) x3 - list( A = 13, B = 23, C = 33 ) x4 - list( A = 14, B = 24, C = 34 ) y1 - list( x1 = x1,

Re: [R] Extracting elements out of list in list in list

2015-01-16 Thread Chel Hee Lee
This approach may not be fancy as what you are looking for. xl - unlist(x) xl[grep(A, names(xl))] f1.x1.A f1.x2.A f2.x3.A f2.x4.A 11 12 13 14 I hope this helps. Chel Hee Lee On 01/16/2015 04:40 AM, Rainer M Krug wrote: Hi Consider the following variable:

Re: [R] Extracting elements out of list in list in list

2015-01-16 Thread Bert Gunter
Chee Hee's approach is both simpler and almost surely more efficient, but I wanted to show another that walks the tree (i.e. the list) directly using recursion at the R level to pull out the desired components. This is in keeping with R's functional programming paradigm and avoids the use of

Re: [R] Extracting elements out of list in list in list

2015-01-16 Thread Brian Diggs
On 1/16/15 9:34 AM, Bert Gunter wrote: Chee Hee's approach is both simpler and almost surely more efficient, but I wanted to show another that walks the tree (i.e. the list) directly using recursion at the R level to pull out the desired components. This is in keeping with R's functional