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

Reply via email to