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 be
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
Brian Diggs 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
>> components. This is in ke
Bert Gunter 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 that your (and Bria
Chel Hee Lee 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, as it would
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" progra
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 regu
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:
--8<---
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 =
9 matches
Mail list logo