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
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
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,
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
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
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,
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:
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
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
9 matches
Mail list logo