[R] Recursive function for lists
John Fox
jfox at mcmaster.ca
Tue Jun 11 21:36:11 CEST 2002
Dear Martin,
At 06:34 PM 6/11/2002 +0200, Martin Maechler wrote:
>unlist() is probably what you can't recall.
>It is a bit different than your flatten() though :
>
> > lst <- list(lst1=list(a=1:3, b=4:6), lst2=list(c=7:9, d=10:12), e=13:15)
>
> > str(ul <- unlist(lst, recursive=FALSE))
>List of 7
> $ lst1.a: int [1:3] 1 2 3
> $ lst1.b: int [1:3] 4 5 6
> $ lst2.c: int [1:3] 7 8 9
> $ lst2.d: int [1:3] 10 11 12
> $ e1 : int 13
> $ e2 : int 14
> $ e3 : int 15
I tried unlist, but don't think that it will solve Eric's problem -- look,
e.g., at how it treats the element $e in the original list.
I rather like Thomas Lumley's solution, which is simpler than mine, though
I think that it will be necessary to unlist the result returned by his
treeapply.
Regards,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list