Skip to content
Prev 241214 / 398500 Next

How to get a specific named element in a nested list

On 11 November 2010 21:08, Janko Thyson <janko.thyson at ku-eichstaett.de> wrote:
Oops - no. The problem was me stupidly renaming the function without
modifying the code.  Try this instead...

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 <- rmatch(el, name)
     if (!is.null(out)) return(out)
   }
 }
}


Sorry about that.

Michael