0

I created a dynamically named data frame in a loop. Now in the same loop, i want another data frame to have the value of this dynamically named data frame

assign(paste("MR", i, sep = '_'), MR2[MR2$PropertyType==MRU[i,1],])

Above mentioned code was used to create a dynamically named data frame. Now i need to put this MR_1's value into MR2_Bound (MR_i is MR_1 for i=1)

MR2_Bound <- value(paste("MR", i, sep = '_'))

This doesn't seem to be working. It puts the character string MR_i in MR2_Bound

  • 2
    Do you really need dynamically named data.frames? This sounds like a design choice that will lead to many problems in R. Not sure where you got the `value()` function from, but if you want to get the value of a variable from the character version of it's name, use `get()`. But again, well written R code generally avoids using `get()` -- there are often much more R-like ways of doing things. If you are doing loops you should probably be using lists. – MrFlick Oct 04 '17 at 14:57
  • I don't want to manually write the names of my data frames. I will try get() thanks – Abhay Saini Oct 04 '17 at 15:00
  • 2
    lists are the "right" way to do this - not manual, less paste-y and buggy then `assign` and `get`. See [how do I make a list of data frames](https://stackoverflow.com/q/17499013/903061) for an introduction. – Gregor Thomas Oct 04 '17 at 15:01
  • Feeling very foolish. get did the work. Thanks a ton Mr Flick – Abhay Saini Oct 04 '17 at 15:03
  • Ok Gregor. I will check it out. Thanks – Abhay Saini Oct 04 '17 at 15:04

0 Answers0