0

If I have a lots of dataframes which are called Df001,Df002,Df003,...,Df100.

How could I access a specific location in every dataframe.

For example, I want to assign:

Df001[1, 3] = a
Df002[2, 4] = b  
... 

(a,b are some values read from a file)

But I don't want to type this codes in details because there are many dataframes needed to be assigned.

Are there some methods that use string to select a dataframe and assign value?

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 8
    I don't know how you wound up with so many data.frame objects in your environment. This sounds like a bad design decision has been made. It probably would make much more sense to store all these data.frames in a single list (especially since they all seem to be related somehow). Then you can easily use the *apply family of functions to perform actions over each item in the list. It would help if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) if you want more specific details. – MrFlick Feb 03 '15 at 06:50
  • Well, because I want to handle many groups of data. There are some relations among these groups of data. Therefore, I want to separate them for managing data easily. I think what I want is like a vector of pointers in C. Every pointer is assigned to every groups of data. If I want to access specific group of data, I can use the corresponding pointer and access that group of data easily. – Wulungching Feb 04 '15 at 07:10

1 Answers1

0

The comment by @MrFlick is appropriate - you should turn all of these into a list or something.

But if you really want to do what you asked, then looping through assign() commands would work. Something like this (it can probably be made prettier):

    for (i in 1:100) {
      tmp.name <- paste0("Df", paste0(paste0(rep("0", 3 - nchar(i)), collapse=""), i))
      tmp.df <- get(tmp.name)
      tmp.df[1, 3] = a
      assign(tmp.name, tmp.df)
    }
LauriK
  • 1,899
  • 15
  • 20
  • Well, because I want to handle many groups of data. There are some relations among these groups of data. Therefore, I want to separate them for managing data easily. I think what I want is like a vector of pointers in C. Every pointer is assigned to every groups of data. If I want to access specific group of data, I can use the corresponding pointer and access that group of data easily. – Wulungching Feb 04 '15 at 07:14
  • Well, you can use C++ through R, using package Rcpp. I've never used these, but there are many resources around for learning how to do that. – LauriK Feb 04 '15 at 08:00