[R] Extracting elements from a list

Forest Floor rhago at comcast.net
Sat Jul 14 14:38:09 CEST 2007


I would love an easy way to extract elements from a list.  

For example, if I want the first element from each of 10 arrays stored 
in a list,  

Lst[[1:10]][1,1]  seems like a logical approach, but gives this error:  
"Error: recursive indexing failed at level 3"

The following workaround is functional but can get annoying/confusing.  

for (i in 1:10){ first.element=c(first.element, Lst[[i]][1,1])  }

Is there a better way to do this?   Thanks for any help!


More information about the R-help mailing list