com>
Emne
20-11-2009 13:19 RE: [R] Accessing list names in
Yet another possibility is to iterate on both values and names simultaneously
using mapply():
df1 <- split(
x=rnorm(n=100, sd=seq(from=1, to=10, each=10)),
f=letters[seq(from=1, to=10, each=10)]
)
mapply(function(x, y) plot(x, ylab=y), df1, names(df1))
Enrique
-Original Message---
Emne
Re: [R] Accessing list names in
lapply
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 Christ
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(
x=rn
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), function(
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
wrote:
>
> Hi,
>
> When using lapply (or sapply) to loop over a list, can I somehow access the
> index of the list from
7 matches
Mail list logo