[R] accessing and preserving list names in lapply

Alexy Khrabrov deliverable at gmail.com
Fri Feb 27 05:27:08 CET 2009

> res <- lapply(1:length(L),do.one)

Actually, I do

res <- lapply(:length(L),function(x)do.one(L[x]))

-- this is the price of needing the element's name, so I have to both  
make do.one extract the name and the meat separately inside, and  
lapply becomes ugly.  Yet the obvious alternatives -- extracting the  
names separately, attaching them back into list elements, etc., -- are  
even uglier.  Something pretty? :)


More information about the R-help mailing list