0

I'm stuck on R because can't figure out how to point to a specific data frame (but could be any type) by its name. This is because I need to combine data from different sources. See the example below:

  • data is split based on cities. The data frames have different amounts of rows and columns. The exact structure of each df isn't important here.

    • df_city1 <- rows = 500, columns = 12
    • df_city2 <- rows = 10, columns = 23
    • df_city3 <- rows = 100, columns = 19
    • df_city4 <- rows = 33, columns = 12
    • df_city5 <- rows = 24, columns = 9
  • now I'll run over another data frame, call it df_master, which includes the names (as string) 'df_city1' until 'df_city5' in a certain column. Depending on the value of that particular 'city' column, a value has to be changed in one of the 5 data frames mentioned above.

  • so basically I need the value of df_master$city to point to the data frame mentioned under the first bullet. Something like

(df_master$city)[3] <- .....

  • 4
    Keep dataframes in a list? `df_master <- list(df_city1, df_city2, ...)` – zx8754 Nov 15 '16 at 13:18
  • Store your data.frames in named lists. Then you can use something like `myList["df_master"]$city[3]`. See gregor's answer to [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for more info. – lmo Nov 15 '16 at 13:19
  • What is your question? what is keeping you from pointing? – Dirk Nachbar Nov 15 '16 at 13:19
  • Look into `get` and `mget` – dww Nov 15 '16 at 22:04

0 Answers0