-
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
. cc
com bjarke.christen...@sydbank.dk
Emne
20-11-2009 13:19 RE: [R] Accessing list names in
lapply
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]
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
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),
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(
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
cc
r-help@r-project.org
Emne
Re: [R] Accessing list names
8 matches
Mail list logo