1

I am iterating through a loop and with every step I would like to give the generated data a different name and save it to the workspace.

    for (l in 1:c){
      data_daily <- data_temp_daily[l,]
      data_daily_time <- data[(l:288*l),2]
      newfile <- paste("data_daily_day", l, sep = "") 
      newfile <- data.frame(data_daily_time, data_daily)
    }

newfile is the filename, which is correctly generated. However, I would like to save my df to the workspace with the newfile name! How can that be accomplished?

THANKS!

Christine Blume
  • 507
  • 3
  • 7
  • 17
  • Check out `?assign`. You should be able to use `assign(newfile, data.frame(....))` – Benjamin Sep 16 '15 at 13:32
  • Simply do not do this, but put these data.frames all together in a list. There are many answers on SO that explain why and how. – Roland Sep 16 '15 at 13:46

2 Answers2

1

Please provide more info about your original datasets.

Let us imagine you want to use the mtcars data. You can easily assign rows or columns to your local environmment with

c = 5 
for (l in 1:c){
  assign( x = paste("data_daily_day", l, sep = ""), value = mtcars[l,] )
}

With assign you paste the name with x = and the data or values with value =. Here we are assigning each rows to our environment.

I can help you further because I dont know what is data_temp_daily and data. Hope this help.

giac
  • 4,261
  • 5
  • 30
  • 59
0

You have the answer to this question here: Dynamic Variable naming in r

You should google a bit before asking

Community
  • 1
  • 1
arodrisa
  • 300
  • 4
  • 17
  • Well, as googling is easier than putting a question here, let us assume that I have done that before. Thanks for the link anyway! – Christine Blume Sep 16 '15 at 13:52