Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Keith Jewell
on: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] >> Im >> Auftrag von Michael Bedward >> Gesendet: Donnerstag, 11. November 2010 10:56 >> An: friedericksen.h...@gmail.com >> Cc: r-h...@stat.math.ethz.ch >> Betreff: Re: [R] How to get a speci

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Michael Bedward
richt- >> Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im >> Auftrag von Michael Bedward >> Gesendet: Donnerstag, 11. November 2010 10:56 >> An: friedericksen.h...@gmail.com >> Cc: r-h...@stat.math.ethz.ch >> Betreff: Re: [R] How

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Friedericksen Hope
Hi Ivan, thank you very much for your detailed explanations and response! Please excuse, that I did not include a reproducible example. Yes, what I am looking for is such a function - but I suspect, that it does not exist already, so I have to write it on my own. Best, Friedericksen On 11/11/

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Janko Thyson
What you want is some sort of indexing nested lists based on names (as we are used to for vectors, for example). As Ivan pointed out, I don't think there's an "out-of-the-box" function in R that supports such indexing as it requires some sort of mapping of the nested list's hierarchical structure.

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Michael Bedward
Hi Friedericksen, This function will do it. No doubt there are more elegant ways :) rmatch <- function(x, name) { pos <- match(name, names(x)) if (!is.na(pos)) return(x[[pos]]) for (el in x) { if (class(el) == "list") { out <- getEl(el, name) if (!is.null(out)) return(o

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Ivan Calandra
Hi, A reproducible example would have been nice, but a correct code even more (you forgot some commas)! So if you meant this: x <- list( list( list(df1,df2), list(df3, list(df4,df5)), list(df6,df7))) check str(x): (I removes the details of each df) List of 1 $ :List of 3 ..