[R] extracting vectors from lists of lists

Jennifer Young Jennifer.Young at math.mcmaster.ca
Fri Dec 11 23:33:18 CET 2009


Good evening

I often have as output from simulations a list of various values, vectors
and matrices.
Supposing that I then run said simulation several times, I often want to
extract a particular result from each simulation for plotting and,
ideally, put it in a matrix.

A simple example

v1 <- 1:5
v2 <- 6:10
other1 <- "stuff"
other2 <- "stuff"

set1 <- list(v1,other1)
names(set1) <- c("vec","other")
set2 <- list(v2,other2)
names(set2) <- c("vec","other")

output <- list(set1, set2)


Is there some form of lapply() that will allow me to extract v1 and v2
(ie, the $vec elements) from both sets?
Bonus if I can then put it into a matrix tidily.

many thanks
Jennifer Young




More information about the R-help mailing list