Skip to content
Prev 174413 / 398506 Next

Creating dataframe names on the fly?

On Fri, Mar 20, 2009 at 7:18 PM, science! <karthik.ram at gmail.com> wrote:
Are you sure you really need to name these dataframes?

Here's a workaround that I use for these cases.  Create your new data
frames and add them to a list, as in

myframes <- list(subset(master,master$SAMPLE=='1'),
m2=subset(master,master$SAMPLE=='2'))

Then when you want to use these things,  you can get the first one as
myframes[[1]]
or myframes[[2]].

You can name the objects inside the list:

names(myframes) <- c("A","B")

This is just as good as referring to them  by name, in my experience.
It also has the benefit that because your dataframes are in a list,
then you can use features like lapply to do things for each dataset.

I'm reading ?assign now, and it appears  you can actually name these things.
[1] "fred4" "mname" "name"  "x"
[1] "fred4"
py
1  -1.04243477
2  -0.66475049
3  -0.08576428
4   0.64369356
5  -0.06828696
6   1.15710627
7  -2.45041700
8   0.40139655
9   0.27320936
10 -0.98028020

pj