Skip to content
Prev 244220 / 398506 Next

fast subsetting of lists in lists

Alexander:

I'm not sure exactly what you want, so the following may be irrelevant...

BUT, noting that data frames ARE lists and IF what you have can then
be abstracted as lists of lists of lists of ... to various depths
AND IF what you want is just to pick out and combined all named
vectors (which could be  columns of data frames) with a given name at
whatever depth they they appear in the lists
THEN it is natural to do this recursively as follows:

vaccuum <- function(x,nm)
## x is a named list (of lists of ...)
## nm in the name searched for
{
  y <- NULL
  for(nmx in names(x)) y <-  c(y,
  {
	z <- x[[nmx]]
	if(nmx==nm)z
	else if(is.list(z))Recall(z,nm)
	})
 y
}

##Example
[1] "a" "b" "c" "d" "e" "f"
[1]  1  2  3  4  5  6 10 11 12 13 14 15

caveat: If perchance this is (at least close to) what you want, it is
likely to be rather inefficient. It also needs some robustifying.

Cheers,
Bert









On Tue, Dec 7, 2010 at 10:54 AM, Alexander Senger
<senger at physik.hu-berlin.de> wrote: