Hi, assuming you know the indexes of names: seq <- 1:100 ; l <- vector("list", 100) ; for (i in seq) {l[[i]] <- list(species=seq[i], name=as.character(seq[i])) }
unlist(l)[seq(2, 200, 2)] #or, as.character(unlist(l)[seq(2, 200, 2)]) > Date: Tue, 13 Aug 2013 12:39:58 +0000 > From: "Novack-Gottshall, Philip M." <pnovack-gottsh...@ben.edu> > To: "r-sig-ecology@r-project.org" <r-sig-ecology@r-project.org> > Subject: [R-sig-eco] Extracting list elements > Message-ID: > <8cf6fe2c677ea94f94fa6285289bae68088ea...@benmail01.ben.pri> > Content-Type: text/plain > > All, > > Please excuse what may be a slightly off-topic question. I'm having trouble > extracting elements from a list of lists. > > Here is an example: > > # Make list of lists: > > seq <- 1:100 > > l <- vector("list", 100) > > for (i in seq) {l[[i]] <- list(species=seq[i], name=as.character(seq[i])) } > > > > # Extract second elements: > > l$name # NULL > > l[seq]$name # also NULL > > s <- unlist(lapply(seq, function(seq) l[[seq]]$name)) > > > > The lapply() call works fine, but it seems quite inefficient or indirect. Can > anyone suggest a more intuitive extraction? > > Thanks, > Phil > > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Phil Novack-Gottshall > Assistant Professor > Department of Biological Sciences > Benedictine University > 5700 College Road > Lisle, IL 60532 > > pnovack-gottsh...@ben.edu<mailto:pnovack-gottsh...@ben.edu> > Phone: 630-829-6514 > Fax: 630-829-6547 > Office: 332 Birck Hall > Lab: 107 Birck Hall > http://www1.ben.edu/faculty/pnovack-gottshall > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology