Re: [R] Accessing list names in lapply

2009-11-20 Thread SIES 73
- Date: Thu, 19 Nov 2009 13:27:08 +0100 From: Bjarke Christensen bjarke.christen...@sydbank.dk Subject: [R] Accessing list names in lapply To: r-help@r-project.org Message-ID: of5533f0b9.99f78ab0-onc1257673.004273ae-c1257673.00446...@bdpnet.dk Content-Type: text/plain; charset=US-ASCII Hi

Re: [R] Accessing list names in lapply

2009-11-20 Thread Bjarke Christensen
. cc com bjarke.christen...@sydbank.dk Emne 20-11-2009 13:19 RE: [R] Accessing list names in lapply

[R] Accessing list names in lapply

2009-11-19 Thread Bjarke Christensen
Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? A trivial example: df1 - split( x=rnorm(n=100, sd=seq(from=1, to=10, each=10)), f=letters[seq(from=1, to=10, each=10)] ) str(df1) #List of 10 # $ a: num [1:10]

Re: [R] Accessing list names in lapply

2009-11-19 Thread Gabor Grothendieck
lapply over the list names rather than the list itself: junk - lapply(names(df1), function(nm) plot(df1[[nm]], ylab = nm)) On Thu, Nov 19, 2009 at 7:27 AM, Bjarke Christensen bjarke.christen...@sydbank.dk wrote: Hi, When using lapply (or sapply) to loop over a list, can I somehow access the

Re: [R] Accessing list names in lapply

2009-11-19 Thread Duncan Murdoch
On 19/11/2009 7:27 AM, Bjarke Christensen wrote: Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? No, but you can loop over the indices in lapply, not just in a for loop. For example, lapply(names(df1),

Re: [R] Accessing list names in lapply

2009-11-19 Thread Romain Francois
Maybe this : http://tolstoy.newcastle.edu.au/R/e4/help/08/04/8720.html Romain On 11/19/2009 01:27 PM, Bjarke Christensen wrote: Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? A trivial example: df1- split(

Re: [R] Accessing list names in lapply

2009-11-19 Thread Henrique Dallazuanna
You can try this: par(mfcol=c(5,2)) lapply(df1, function(x){ nm - names(eval(as.list(sys.call(-1))[[2]]))[as.numeric(gsub([^0-9], , deparse(substitute(x] plot(x, main = nm) }) On Thu, Nov 19, 2009 at 10:27 AM, Bjarke

Re: [R] Accessing list names in lapply

2009-11-19 Thread Bjarke Christensen
cc r-help@r-project.org Emne Re: [R] Accessing list names