0

I have created multiple data frames by using below code :

assign(paste0("DF_VID", i) , subset(df, df$VID == unique(mydata$VID)[i]))

I would like to add new column class in each created data frame (DF_VID1, DF_VID2,...). I tried ("DF_VID", i)[,"class"] <- 0 but it is showing error and when I try with DF_VID1[, "class"] <- 0 then it runs but just for one data frame. I want to know how to add new column in each data frame dynamically.

989
  • 11,117
  • 5
  • 24
  • 45
sanman
  • 1
  • 3
  • 1
    You might want to consider using a list to store your data frames, if the names only differ by a number, q.v. [this SO post](http://stackoverflow.com/questions/2679193/how-to-name-variables-on-the-fly-in-r). – Tim Biegeleisen Jun 17 '16 at 14:48
  • 1
    Also see [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) on putting data.frames into lists as well as how to work with them once they are in a list. – lmo Jun 17 '16 at 14:56
  • That means indeed you need to work with a list and should consider `allDFlist – Eric Lecoutre Jun 17 '16 at 15:02
  • Thanks to all. @Eric Lecoutre: perfect solution – sanman Jun 17 '16 at 16:26

0 Answers0