I'm merging some data frames that are stored in a list. For that purpose I'm using a for-loop with a .df command. Now, I would like to use the name of the data frame as suffixes in a paste inside my loop.
Is there a way, using the for ( .df in [list]) { command that I can subtract the name of the data frame currently in .df inside the loop?
Say I have this list with three data frames,
a <- list(A = data.frame(a=runif(2), b=runif(2)),
B = data.frame(a=runif(2), b=runif(2)),
C = data.frame(a=runif(2), b=runif(2)))
a
$A
a b
1 0.2833226 0.6242624
2 0.1741420 0.1707722
$B
a b
1 0.55073381 0.6082305
2 0.08678421 0.5192457
$C
a b
1 0.02788030 0.1392156
2 0.02171247 0.7189846
Now, I would like to use this loop,
for ( .df in a) {
print(['command I do not know about'])
}
and then have the [command I do not know about] print out A, B, C (i.e. the name of the data frame in .df).
Can I do that?
Update 2012-04-28 20:11:58 PDT
Here is a snipped of what I expect form my output using the simple loop from above,
for ( .df in a) {
print(['command I do not know about'](a))
}
[1] "A"
[1] "B"
[1] "C"
I could obtain this using,
for (x in names(a)) {
print(x)
}
but due to the nature of what I am doing I would like to use the for ( .df in [list]) { command in my for-loop.
for (nm in names(a)) { print(nm); .df = a[[nm]] }?.dfelement. Sorry for not being more specific in my initial question.