Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_<-list() for(i in 1:5){ Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142479.html Sent from the R help mailing list archive at Nabble.com.
Someone is bound to know a better way, but... subset(unlist(Version1_), subset=names(unlist(Version1_))=="First") LCOG1 wrote> > Hi everyone, > I looked around the list for a while but couldn't find a solution to my > problem. I am storing some results to a simulation in a list and for each > element i have two separate vectors(is that what they are called, correct > my vocab if necessary). See below > > Version1_<-list() > for(i in 1:5){ > Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) > } > > What I want is to put all of the elements' 'First' vectors into a single > list to box plot. But whats a more elegant solution to the below? > > c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) > > since i have 50 or more simulations this is impractical and sloppy. Do I > need to store my data differently or is their a solution on the back end? > Thanks all. > > Josh >-- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142884.html Sent from the R help mailing list archive at Nabble.com.
How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 <jroll at lcog.org> wrote:> Hi everyone, > ? I looked around the list for a while but couldn't find a solution to my > problem. ?I am storing some results to a simulation in a list and for each > element i have two separate vectors(is that what they are called, correct my > vocab if necessary). See below > > Version1_<-list() > for(i in 1:5){ > ? ? ? ?Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) > } > > What I want is to put all of the elements' 'First' vectors into a single > list to box plot. But whats a more elegant solution to the below? > > c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) > > since i have 50 or more simulations this is impractical and sloppy. ?Do I > need to store my data differently or is their a solution on the back end? > Thanks all. > > Josh >-- Sarah Goslee http://www.functionaldiversity.org