0

I think this one is easy but I still can't figure it out and I really need help with this. I've looked everywhere but still couldn't find it.

Let's say I have this vector:

filenames <- c("fn1", "fn2", "fn3")

And I want to associate them with an dataframe that is created according to a function, that is generated at that time

df|name from filenames[i]| <- df

so it would return these dataframes

dffn1
dffn2
dffn3

I hope I made myself clear. My problem is create a new data frame and name it according to a list or whatever, in a for loop.

joran
  • 169,992
  • 32
  • 429
  • 468
Lucca Ramalho
  • 573
  • 1
  • 6
  • 16
  • 2
    This is not a fun pattern to work with in R. A list of data.frames rather than a bunch of variables would be better. See this answer: https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames – MrFlick Feb 06 '18 at 19:08
  • You can create all the dataframes and store them in a list using a string (`names(ListofDFs)=nameString`), then name the list. It's also easier for R to work with a list of df's instead of a bunch of df's. – Cris Feb 06 '18 at 19:11

1 Answers1

0

You can use assign to achieve what you want.

for(nms in filenames){
 assign(paste('df',nms,sep=''), df) }
jasbner
  • 2,253
  • 12
  • 24